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

SendMsg Method Not-Concurrency Safe #2094

Closed
steve-gray opened this issue May 19, 2018 · 3 comments
Closed

SendMsg Method Not-Concurrency Safe #2094

steve-gray opened this issue May 19, 2018 · 3 comments

Comments

@steve-gray
Copy link

What version of gRPC are you using?

We are using go 1.10, with a GRPC 3 service using the latest versions of grpc-go and the protoc code generator.

What version of Go are you using (go version)?

1.10

What operating system (Linux, Windows, …) and version?

OSX, Linux

What did you do?

We have a service where clients connect with a subscription profile, and we respond each time an item arrives on the corresponding response stream. We recently changed the sending send to use multiple goroutines to fetch data from multiple sources, and send them all to the same client.

What did you expect to see?

Concurrent sends should serialize onto the connection internally for transmission to the remote side. We were not able to achieve this until we wrapped the Send(item) call with a sync.Mutex.

What did you see instead?

It appears that the SendMsg method is not thread/goroutine safe - and we observed that during a race, one of the requests would succeed, with all others hanging indefinately - as if there's a mechanism that's trying to mitigate this, but it's not working as-intended.

@electronjoe
Copy link

FWIW I ran across your report while troubleshooting another proximal issue - the documentation for
SendMsg indicates it is NOT safe to simultaneously use from two goroutines:

// It's safe to have a goroutine calling SendMsg and another goroutine calling
// recvMsg on the same stream at the same time.
// But it is not safe to call SendMsg on the same stream in different goroutines.

https://godoc.org/google.golang.org/grpc#Stream

@steve-gray
Copy link
Author

steve-gray commented May 20, 2018 via email

@lyuxuan
Copy link
Contributor

lyuxuan commented May 21, 2018

This has been discussed in #1879, please refer to it for more info.

@dfawley dfawley closed this as completed May 24, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Nov 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants