Skip to content

Commit

Permalink
transport: hide Stream string when stored in context
Browse files Browse the repository at this point in the history
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 committed Apr 7, 2017
1 parent 9f9c190 commit 08f98ff
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ func (s *Stream) finish(st *status.Status) {
close(s.done)
}

func (s *Stream) GoString() string {
// so context.String() won't race when printing %#v
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 08f98ff

Please sign in to comment.