Fix data race between stream Drain and concurrent Read - #161
Merged
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
somaz94
added a commit
to somaz94/somaz94
that referenced
this pull request
Jul 14, 2026
somaz94
marked this pull request as ready for review
July 14, 2026 05:47
slinkydeveloper
approved these changes
Jul 14, 2026
slinkydeveloper
left a comment
Contributor
There was a problem hiding this comment.
This is great, thank you!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
stream.ReadtakesrLockbefore readingc.r, butDrainranio.Copy(io.Discard, c.r)in a goroutine without the lock, racing with anin-flight read on the same reader (#156).
This takes
rLockin the drain goroutine so the two paths are serialized, andmakes the result channel buffered so the goroutine does not strand if
Drainreturns on the timeout path.
Validation (local):
server/stream_test.goreproducing the race.go test -race ./server/reports the race on the current code and passes with the fix (verified by
reverting stream.go).
go vet ./...,go build ./...,go test -short ./...all pass.Note: CI runs
go test -short(no-race), so this regression only shows under-race. Runninggo test -race ./server/catches it.Closes #156