From cf4510a13105a12eeeb6879f3c70051501634589 Mon Sep 17 00:00:00 2001 From: Oleg Guba Date: Mon, 14 Oct 2024 14:16:22 -0700 Subject: [PATCH] [serverWatchStream] terminate recvLoop on sws.close() --- server/etcdserver/api/v3rpc/watch.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/etcdserver/api/v3rpc/watch.go b/server/etcdserver/api/v3rpc/watch.go index abb465e21d7..6781c468ada 100644 --- a/server/etcdserver/api/v3rpc/watch.go +++ b/server/etcdserver/api/v3rpc/watch.go @@ -347,11 +347,17 @@ func (sws *serverWatchStream) recvLoop() error { id := uv.CancelRequest.WatchId err := sws.watchStream.Cancel(mvcc.WatchID(id)) if err == nil { - sws.ctrlStream <- &pb.WatchResponse{ + wr := &pb.WatchResponse{ Header: sws.newResponseHeader(sws.watchStream.Rev()), WatchId: id, Canceled: true, } + select { + case sws.ctrlStream <- wr: + case <-sws.closec: + return nil + } + sws.mu.Lock() delete(sws.progress, mvcc.WatchID(id)) delete(sws.prevKV, mvcc.WatchID(id))