Skip to content
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

bidi streams have racy read caused by goroutine that closes over local variable #583

Closed
jhump opened this issue Mar 29, 2018 · 0 comments
Closed

Comments

@jhump
Copy link
Contributor

jhump commented Mar 29, 2018

In the code generated for a bidi streaming endpoint, a closure named handleSend captures a variable named err from the enclosing function. This function is then executed in its own goroutine. That means there are racy reads and writes between that goroutine and the one that spawned it (which is also using err as a local variable in later statements). There is no attempt at synchronization of any kind between the two goroutines.

When I run do go test -race with a test that involves a bidi stream through grpc-gateway, it triggers the race detector which causes the test to always fail. And it's pretty consistent.

And the fix is easy: it appears to be an accidental closure -- a typo that uses = instead of :=. There is no need for the two goroutines to share this variable.

You can find a fix here: #575

adasari pushed a commit to adasari/grpc-gateway that referenced this issue Apr 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant