-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
TBufferedServer: Avoid channel close/send race on Stop #2583
TBufferedServer: Avoid channel close/send race on Stop #2583
Conversation
TBufferedServer.Close() may close the data channel before Serve detects it. Move chan close() to Serve to prevent a panic caused by sending on a closed channel. See also golang/go#27769 (comment) === RUN TestTBufferedServer_SendReceive ================== WARNING: DATA RACE Write at 0x00c000074850 by goroutine 9: runtime.closechan() /home/travis/.gimme/versions/go1.15.2.linux.amd64/src/runtime/chan.go:352 +0x0 github.com/jaegertracing/jaeger/cmd/agent/app/servers.(*TBufferedServer).Stop() ... Previous read at 0x00c000074850 by goroutine 10: runtime.chansend() /home/travis/.gimme/versions/go1.15.2.linux.amd64/src/runtime/chan.go:158 +0x0 github.com/jaegertracing/jaeger/cmd/agent/app/servers.(*TBufferedServer).Serve() /home/travis/gopath/src/github.com/jaegertracing/jaeger/cmd/agent/app/servers/tbuffered_server.go:97 +0x264 ... ================== testing.go:1042: race detected during execution of test --- FAIL: TestTBufferedServer_SendReceive (0.01s) Closes jaegertracing#2577 Signed-off-by: Carl Henrik Lunde <[email protected]>
The downside is that the channel will not be closed if Serve is never called, but I can't see any way this will happen with the current code. |
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.
Your PR is changing how Close and Read are interacting, not Close and Send.
Not sure if I follow, I believe this is what happens on
After patch, 4000 runs no error
Before patch, typically it fails before 30 runs:
|
Codecov Report
@@ Coverage Diff @@
## master #2583 +/- ##
==========================================
- Coverage 95.31% 95.30% -0.02%
==========================================
Files 208 208
Lines 9281 9281
==========================================
- Hits 8846 8845 -1
- Misses 356 357 +1
Partials 79 79
Continue to review full report at Codecov.
|
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.
Thanks!
TBufferedServer.Close() may close the data channel before
Serve detects it. Move chan close() to Serve to prevent
a panic caused by sending on a closed channel.
See also golang/go#27769 (comment)
Closes #2577
Signed-off-by: Carl Henrik Lunde [email protected]