소스 검색

grpcproxy: tear down watch when client context is done

If client closes but all watch streams are not canceled, the outstanding
watch will wait until it is canceled, causing watch server to potentially
wait forever to close.

Fixes #7102
Anthony Romano 9 년 전
부모
커밋
e179225f28
1개의 변경된 파일12개의 추가작업 그리고 12개의 파일을 삭제
  1. 12 12
      proxy/grpcproxy/watch.go

+ 12 - 12
proxy/grpcproxy/watch.go

@@ -122,23 +122,23 @@ func (wp *watchProxy) Watch(stream pb.Watch_WatchServer) (err error) {
 		defer func() { stopc <- struct{}{} }()
 		defer func() { stopc <- struct{}{} }()
 		wps.sendLoop()
 		wps.sendLoop()
 	}()
 	}()
-	if leaderc != nil {
-		go func() {
-			defer func() { stopc <- struct{}{} }()
-			select {
-			case <-leaderc:
-			case <-ctx.Done():
-			}
-		}()
-	}
+	// tear down watch if leader goes down or entire watch proxy is terminated
+	go func() {
+		defer func() { stopc <- struct{}{} }()
+		select {
+		case <-leaderc:
+		case <-ctx.Done():
+		case <-wp.ctx.Done():
+		}
+	}()
 
 
 	<-stopc
 	<-stopc
+	cancel()
+
 	// recv/send may only shutdown after function exits;
 	// recv/send may only shutdown after function exits;
 	// goroutine notifies proxy that stream is through
 	// goroutine notifies proxy that stream is through
 	go func() {
 	go func() {
-		if leaderc != nil {
-			<-stopc
-		}
+		<-stopc
 		<-stopc
 		<-stopc
 		wps.close()
 		wps.close()
 		wp.wg.Done()
 		wp.wg.Done()