Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transport: hide Stream string when stored in context #1167

Merged
merged 1 commit into from
Apr 7, 2017

Conversation

heyitsanthony
Copy link
Contributor

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, use "" as the GoString.

@heyitsanthony
Copy link
Contributor Author

The data race that's showing up:

WARNING: DATA RACE
Write at 0x00c423dbbcf9 by goroutine 683:
  google.golang.org/grpc/transport.(*http2Server).handleData()
      /home/jenkins/workspace/etcd-proxy/gopath/src/google.golang.org/grpc/transport/http2_server.go:379 +0x3aa
  google.golang.org/grpc/transport.(*http2Server).HandleStreams()
      /home/jenkins/workspace/etcd-proxy/gopath/src/google.golang.org/grpc/transport/http2_server.go:287 +0xa15
  google.golang.org/grpc.(*Server).serveStreams()
      /home/jenkins/workspace/etcd-proxy/gopath/src/google.golang.org/grpc/server.go:451 +0x1db
  google.golang.org/grpc.(*Server).serveNewHTTP2Transport()
      /home/jenkins/workspace/etcd-proxy/gopath/src/google.golang.org/grpc/server.go:438 +0x4e3
  google.golang.org/grpc.(*Server).handleRawConn()
      /home/jenkins/workspace/etcd-proxy/gopath/src/google.golang.org/grpc/server.go:415 +0x5e7

Previous read at 0x00c423dbbcf8 by goroutine 422:
  reflect.typedmemmove()
      /usr/local/go/src/runtime/mbarrier.go:253 +0x0
  reflect.packEface()
      /usr/local/go/src/reflect/value.go:112 +0x11c
  reflect.valueInterface()
      /usr/local/go/src/reflect/value.go:949 +0x18c
  reflect.Value.Interface()
      /usr/local/go/src/reflect/value.go:919 +0x51
  fmt.(*pp).printValue()
      /usr/local/go/src/fmt/print.go:694 +0x3aea
  fmt.(*pp).printValue()
      /usr/local/go/src/fmt/print.go:848 +0x27dc
  fmt.(*pp).printArg()
      /usr/local/go/src/fmt/print.go:682 +0x1b1
  fmt.(*pp).doPrintf()
      /usr/local/go/src/fmt/print.go:998 +0x1cad
  fmt.Sprintf()
      /usr/local/go/src/fmt/print.go:196 +0x77
  context.(*valueCtx).String()
      /usr/local/go/src/context/context.go:471 +0x16a
  fmt.(*pp).handleMethods()
      /usr/local/go/src/fmt/print.go:596 +0x40a
  fmt.(*pp).printArg()
      /usr/local/go/src/fmt/print.go:679 +0x132
  fmt.(*pp).doPrintf()
      /usr/local/go/src/fmt/print.go:998 +0x1cad
  fmt.Sprintf()
      /usr/local/go/src/fmt/print.go:196 +0x77
  context.(*valueCtx).String()
      /usr/local/go/src/context/context.go:471 +0x16a
  fmt.(*pp).handleMethods()
      /usr/local/go/src/fmt/print.go:596 +0x40a
  fmt.(*pp).printArg()
      /usr/local/go/src/fmt/print.go:679 +0x132
  fmt.(*pp).doPrintf()
      /usr/local/go/src/fmt/print.go:998 +0x1cad
  fmt.Sprintf()
      /usr/local/go/src/fmt/print.go:196 +0x77
  context.(*valueCtx).String()
      /usr/local/go/src/context/context.go:471 +0x16a
  fmt.(*pp).handleMethods()
      /usr/local/go/src/fmt/print.go:596 +0x40a
  fmt.(*pp).printArg()
      /usr/local/go/src/fmt/print.go:679 +0x132
  fmt.(*pp).doPrintf()
      /usr/local/go/src/fmt/print.go:998 +0x1cad
  fmt.Sprintf()
      /usr/local/go/src/fmt/print.go:196 +0x77
  context.(*cancelCtx).String()
      /usr/local/go/src/context/context.go:332 +0xcc
  fmt.(*pp).handleMethods()
      /usr/local/go/src/fmt/print.go:596 +0x40a
  fmt.(*pp).printArg()
      /usr/local/go/src/fmt/print.go:679 +0x132
  fmt.(*pp).doPrintf()
      /usr/local/go/src/fmt/print.go:998 +0x1cad
  fmt.Sprintf()
      /usr/local/go/src/fmt/print.go:196 +0x77
  github.com/coreos/etcd/clientv3.(*watcher).Watch()
      /home/jenkins/workspace/etcd-proxy/gopath/src/github.com/coreos/etcd/clientv3/watch.go:250 +0x48c
  github.com/coreos/etcd/clientv3/concurrency.(*Election).observe()
      /home/jenkins/workspace/etcd-proxy/gopath/src/github.com/coreos/etcd/clientv3/concurrency/election.go:178 +0x461

@xiang90
Copy link
Contributor

xiang90 commented Apr 5, 2017

/cc @menghanl @MakMukhi

can you take a look?

@menghanl
Copy link
Contributor

menghanl commented Apr 5, 2017

How about implementing GoString() on Stream?
It can return the pointer and the method name. Something like

func (s *Stream) GoString() string {
    return fmt.Sprintf("<stream: %p, %v>", s, s.method)
}

@heyitsanthony heyitsanthony force-pushed the stream-ctx-string branch 2 times, most recently from 08f98ff to 7e616f5 Compare April 7, 2017 05:15
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.
@heyitsanthony
Copy link
Contributor Author

@menghanl OK, all fixed.

Copy link
Contributor

@menghanl menghanl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. LGTM.

@xiang90
Copy link
Contributor

xiang90 commented Apr 7, 2017

@menghanl thank you so much for the quick review.

@menghanl menghanl merged commit 087f3d6 into grpc:master Apr 7, 2017
@xiang90
Copy link
Contributor

xiang90 commented Apr 7, 2017

@menghanl can we get a release soon? this currently blocks our CI to get things done :P

@heyitsanthony heyitsanthony deleted the stream-ctx-string branch April 7, 2017 18:19
menghanl pushed a commit that referenced this pull request Apr 7, 2017
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.
@menghanl
Copy link
Contributor

menghanl commented Apr 7, 2017

@xiang90 Just did a v1.2.1 release on v1.2.x branch. This fix in included in that release.

@menghanl menghanl added the 1.3 label Apr 8, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants