Skip to content

Commit

Permalink
transport: implement GoString on Stream (#1167)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Anthony Romano authored and menghanl committed Apr 7, 2017
1 parent 9f9c190 commit 087f3d6
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand Down

0 comments on commit 087f3d6

Please sign in to comment.