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: time.After(math.MaxInt64) kills all time.After() instances #4903
Labels
Milestone
Comments
When creating a timer, the duration is added to the current time in nanoseconds and stored in an int64. This overflows for long durations, storing a negative "when" time. In package runtime, the pending timers are stored in a queue that is sorted by "when". The timerproc goroutine periodically checks this queue to see if any new events need to be fired. The way it checks is by iterating through the timers and computing delta = t->when - now; and stopping if delta >= 0. If that loop exits with delta < 0, it's assumed that there's no work to do and the goroutine is parked. I think one important fix is to make timerproc use a separate flag to mean "didn't find anything to do." instead of using a negative delta. The other important fix is to prevent "when" from overflowing maxint64 in the first place. I don't think Sleep and After should panic on overly large durations. Probably it should just truncate when to maxint64 in those cases. I don't think this matters; nobody will be sleeping in go programs past the year 2262. Or, if they are, our descendants can revisit this a century before then. |
On further examination, the runtime code looks fine. The CL above fixes the issue in the time package. Owner changed to @adg. Status changed to Started. |
This issue was closed by revision 89cf67e. Status changed to Fixed. |
Comment 10 by alec@swapoff.org: No problem, thanks for fixing it so promptly! |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
by alec@swapoff.org:
The text was updated successfully, but these errors were encountered: