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 9aa08c5 commit 377fdf6
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 @@ -338,6 +338,12 @@ func (s *Stream) Read(p []byte) (n int, err error) {
return
}

// 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 377fdf6

Please sign in to comment.