From 377fdf6b168a683dacf558f1a2c9332e0e802c35 Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Fri, 7 Apr 2017 11:16:52 -0700 Subject: [PATCH] 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. --- transport/transport.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/transport/transport.go b/transport/transport.go index beb0a520a573..0fc4c146f90b 100644 --- a/transport/transport.go +++ b/transport/transport.go @@ -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("", s, s.method) +} + // The key to save transport.Stream in the context. type streamKey struct{}