-
Notifications
You must be signed in to change notification settings - Fork 3.4k
refactor: Remove time.After
from any Loops
#14380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
7aa2fd5
to
8734c83
Compare
6d02ddf
to
f1cd386
Compare
test-me-please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nathanjsweet the tests are failing in this line
cilium/test/provision/compile.sh
Line 113 in 712db13
sudo -u vagrant -H -E make LOCKDEBUG=1 SKIP_K8S_CODE_GEN_CHECK=false SKIP_DOCS=true |
f1cd386
to
e061447
Compare
`time.After` is not garbage collected until after its channel fires once. In situations where it is called repeatedely this *can* lead to significant memory build up. Instead of creating a new timer object for every iteration, a single timer, with a hard-reset mechanism, is used in situations where `time.After` is being called repeatedely. See the following article for details: https://medium.com/@oboturov/golang-time-after-is-not-garbage-collected-4cbc94740082 pkg: Add inctimer The new inctimer package is useful for boiling down the monotonous taks of "hard" resetting the reused timer. In order to reuse a timer to solve the `time.After` garbage collection problem the timer must be stopped, have its channel cleared (or not, if it was already read), and then reset. Duplicating this code all over the cilium code base seems superfluous, a small package that mimics the more terse `time.After` method seems more desireable. Signed-off-by: Nate Sweet <nathanjsweet@pm.me>
e061447
to
c626046
Compare
test-me-please |
looks like we hit some kind of GH outage, rerunning tests |
test-me-please |
retest-runtime |
retest-gke |
The previous runtime test failed with
|
Marking for backport to v1.9 as this is an important change to have for stable releases. |
time.After
is not garbage collected until afterits channel fires once. In situations where it is called
repeatedly this can lead to significant memory build-up.
Instead of creating a new timer object for every iteration,
a single timer, with a hard-reset mechanism, is used in
situations where
time.After
is being called repeatedly.See the following article for details:
https://medium.com/@oboturov/golang-time-after-is-not-garbage-collected-4cbc94740082
pkg: Add inctimer
The new inctimer package is useful for boiling down the monotonous
task of "hard" resetting the reused timer. In order to reuse a timer
to solve the
time.After
garbage collection problem the timer mustbe stopped, have its channel cleared (or not, if it was already read),
and then reset. Duplicating this code all over the cilium code base
seems superfluous, a small package that mimics the more terse
time.After
method seems more desirable.Signed-off-by: Nate Sweet nathanjsweet@pm.me
fixes: #14219