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
time: example of After includes a bad practice #43009
Comments
/cc @rsc |
@snadrus What do you recommend instead? The GC behavior is clearly documented, and the alternative involves not using time.After at all. But still seems useful to have an example for time.After. |
The risk is with "select" statements. Adding that to the documentation could help. An example could have goroutine blocking: https://play.golang.org/p/0eUOnvITpcg |
@snadrus your example would be better written with time.Sleep. |
Then perhaps it would be best to advise against this function since there
are no safe uses except those covered better by other functions.
…On Fri, Dec 4, 2020, 6:12 PM Caleb Spare ***@***.***> wrote:
@snadrus <https://github.com/snadrus> your example would be better
written with time.Sleep.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#43009 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAOU4LS5EW6K3PDY3PNCRQDSTGJHVANCNFSM4UN5XLHA>
.
|
There are many safe uses of It's true that if you have many calls to But it's perfectly fine to use |
That's quite a list of undocumented gotchas. If you're content with it, then I suppose we can close this bug. |
I only count a single gotcha, and it is documented. |
That single root cause is 3 "use" gotchas;
|
In order to have a real problem, all three must be true. |
Does this issue reproduce with the latest release? Yes
What operating system? All
What did you do?
Used the time.After example in production, specifically:
case <-time.Now().After(5*time.Minute):
What did you expect to see?
A sensible scaling of the example as load increased.
What did you see instead?
https://medium.com/@oboturov/golang-time-after-is-not-garbage-collected-4cbc94740082
Using this in a switch clause fails to account for the lack of on-demand garbage collection (documented) which (at scale) becomes a problem consuming GB of memory and causing GC churn.
The text was updated successfully, but these errors were encountered: