Procházet zdrojové kódy

v3rpc: do not send closing event

When a watch stream closes, both of the watcher.Chan and closec
will be closed.

If watcher.Chan is closed, we should not send out the empty event.
Sending the empty is wrong and waste a lot of CPU resources.
Instead we should just return.
Xiang Li před 10 roky
rodič
revize
3cf90a4dff
1 změnil soubory, kde provedl 4 přidání a 1 odebrání
  1. 4 1
      etcdserver/api/v3rpc/watch.go

+ 4 - 1
etcdserver/api/v3rpc/watch.go

@@ -61,7 +61,10 @@ func (ws *watchServer) Watch(stream pb.Watch_WatchServer) error {
 func sendLoop(stream pb.Watch_WatchServer, watcher storage.Watcher, closec chan struct{}) {
 func sendLoop(stream pb.Watch_WatchServer, watcher storage.Watcher, closec chan struct{}) {
 	for {
 	for {
 		select {
 		select {
-		case e := <-watcher.Chan():
+		case e, ok := <-watcher.Chan():
+			if !ok {
+				return
+			}
 			err := stream.Send(&pb.WatchResponse{Event: &e})
 			err := stream.Send(&pb.WatchResponse{Event: &e})
 			if err != nil {
 			if err != nil {
 				return
 				return