Explorar o código

grpcproxy: fix a data race

Xiang Li %!s(int64=9) %!d(string=hai) anos
pai
achega
56cfe40184
Modificáronse 1 ficheiros con 2 adicións e 1 borrados
  1. 2 1
      proxy/grpcproxy/watch.go

+ 2 - 1
proxy/grpcproxy/watch.go

@@ -56,6 +56,7 @@ func NewWatchProxy(c *clientv3.Client) pb.WatchServer {
 func (wp *watchProxy) Watch(stream pb.Watch_WatchServer) (err error) {
 	wp.mu.Lock()
 	wp.nextStreamID++
+	sid := wp.nextStreamID
 	wp.mu.Unlock()
 
 	sws := serverWatchStream{
@@ -64,7 +65,7 @@ func (wp *watchProxy) Watch(stream pb.Watch_WatchServer) (err error) {
 		singles:  make(map[int64]*watcherSingle),
 		inGroups: make(map[int64]struct{}),
 
-		id:         wp.nextStreamID,
+		id:         sid,
 		gRPCStream: stream,
 
 		watchCh: make(chan *pb.WatchResponse, 1024),