Hi,
I couldn’t find any mention in the doc as to whether or not it’s safe
to call Send() from multiple goroutines concurrently on a stream
object. It appears that I mistakenly assumed that it was, but it’s
not.
Send() calls x.ServerStream.SendMsg(m) in the protoc-generated code.
This takes us here:
https://github.com/grpc/grpc-go/blob/89f694edb447e224bd0ffff7a03f9161ce486482/stream.go#L198
where we do:
out, err := encode(cs.codec, m, cs.cp, cs.cbuf)
and encode() is going to write into the bytes.Buffer passed as the
last argument (cs.cbuf) and no lock is acquired in the process.
So two goroutines calling Send() concurrently will step over each
other’s toes and lead to a corrupted protobuf being sent.
Took us a while to figure that one out as the race detector doesn’t
detect this one for some reason.
Before filing an issue on GitHub I just wanted to check whether this
was indeed the intended behavior and we have to add our own locking
around the Stream objects?
--
Benoit "tsuna" Sigoure