-
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
context: WithTimeout scheduling is less deterministic than time.Timer on Windows #44608
Comments
This may be an artifact of Windows timer resolution or other timer flakiness (see #8687, #44343, #29485, #28255, and possibly others) — it is possible that the |
Yes, this looks like a duplicate of #44343. Effectively, time.Sleep, time.Ticker and time.Timer all have granularity of 15ms on Windows. This, means that the minimum sleep is ~15ms. If you change the code to:
It does behave the same way, however, of course, it doesn't solve the underlying problem. |
Yes, seems like a duplicate of #44343. Actually, this behavior doesn't bother me so much anymore as I am aware of it now. This is just a development machine. The dev+prod use a Linux distro.
I played around on Win10 and actually Just for reference. The following benchmark with 1.16: package main
import (
"context"
"fmt"
"time"
"github.com/loov/hrtime"
)
func main() {
b := hrtime.NewBenchmark(100000)
for b.Next() {
ctx := context.Background()
tCtx1, tCancel1 := context.WithTimeout(ctx, 1 * time.Nanosecond)
tCtx2, tCancel2 := context.WithTimeout(ctx, 5 * time.Millisecond)
select {
case <- tCtx1.Done():
tCancel2()
case <- tCtx2.Done():
tCancel1()
}
}
fmt.Println(b.Histogram(10))
} On Win10:
On Alpine 9.2.0 (Linux 4.19.121-linuxkit x86_64) @ Docker:
These results differ from the ones of #44343. |
Duplicate of #44343 |
What version of Go are you using (
go version
)?I have tried with
go version go1.15.2 windows/amd64
andgo version go1.16 windows/amd64
.Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: