Skip to content

Fix data race between stream Drain and concurrent Read - #161

Merged
slinkydeveloper merged 1 commit into
restatedev:mainfrom
somaz94:fix/drain-read-race
Jul 14, 2026
Merged

Fix data race between stream Drain and concurrent Read#161
slinkydeveloper merged 1 commit into
restatedev:mainfrom
somaz94:fix/drain-read-race

Conversation

@somaz94

@somaz94 somaz94 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

stream.Read takes rLock before reading c.r, but Drain ran
io.Copy(io.Discard, c.r) in a goroutine without the lock, racing with an
in-flight read on the same reader (#156).

This takes rLock in the drain goroutine so the two paths are serialized, and
makes the result channel buffered so the goroutine does not strand if Drain
returns on the timeout path.

Validation (local):

  • Added server/stream_test.go reproducing 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. Running go test -race ./server/ catches it.

Closes #156

@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@somaz94

somaz94 commented Jul 14, 2026

Copy link
Copy Markdown
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
somaz94 marked this pull request as ready for review July 14, 2026 05:47

@slinkydeveloper slinkydeveloper left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, thank you!

@slinkydeveloper
slinkydeveloper merged commit 668b4af into restatedev:main Jul 14, 2026
2 of 3 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Data race: (*stream).Drain reads the request body without rLock, racing readInputLoop

2 participants