-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
runtime: usleep does not check for early wakeup #40653
Comments
The runtime uses SA_RESTART when installing signal handlers, which I am pretty sure prevents nanosleep from ever returning EINTR. Also, note the comment just before making the system call: the invocation is equivalent to Have you observed shorter sleeps due to signal interruptions? I am reading the man page and I cannot see other circumstances for an error: can you think of any other reason why nanosleep might return an error, considering the fact that signal handlers are installed with SA_RESTART? In the man page, I see EFAULT for a bad req pointer, EINTR for a signal interruption, and EINVAL for invalid timespec values, which I imagine the surrounding runtime code guards against. |
Does this ever cause a problem? The |
The only places where usleep needs to sleep for the expected length are:
The first is in sysmon, where shortened sleep would result in background work happening faster than expected. The second is in tickspersecond, which is used by profiles to turn CPU time into CPU cycles. The third is when a process crashes: we sleep 5 seconds while the SIGQUIT signals are going around causing stack traces. Assuming this actually works, it seems like strong proof that sleeping through signals is fine. As Cherry said, have you ever observed a short sleep? Does this actually happen? |
I retitled this; the question of whether an early wakeup is even possible remains. |
|
@acln0 The |
The 5 second sleep in We could block signals around the call to We could also block signals around the call to |
Moving to Unplanned since it's still not clear this is actually a problem. |
I would also like to confirm that early wakeup is possible. Here is a simple test case: func main() {
start := time.Now()
runtime.SetBlockProfileRate(42)
fmt.Println(time.Since(start))
} Without wakeup, one would expect this to take at least 100ms due to the
However, for later go versions I see this:
I suspect that this is due to async preemption signals introduced in Go 1.14. As far as impact is concerned, this could reduce the accuracy of block profiling. |
After calling nanosleep, it did not check whether the return value is 0, resulting in inaccurate waiting time
The text was updated successfully, but these errors were encountered: