transport: implement GoString on Stream (#1167)

So context.String() won't  race when printing %#v.

It is not thread-safe to call context.String() on any context with a
stream value since valueCtx will use %#v to access all of the Stream
fields without holding a lock. Instead, print the Stream's pointer and
method for its GoString.
This commit is contained in:
Anthony Romano
2017-04-07 11:16:52 -07:00
committed by Menghan Li
parent 9f9c190692
commit 087f3d6e02

View File

@ -341,6 +341,12 @@ func (s *Stream) finish(st *status.Status) {
close(s.done)
}
// GoString is implemented by Stream so context.String() won't
// race when printing %#v.
func (s *Stream) GoString() string {
return fmt.Sprintf("<stream: %p, %v>", s, s.method)
}
// The key to save transport.Stream in the context.
type streamKey struct{}