From 77607356d9b93c1802eed71fe4d3201cd54c7935 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() Signed-off-by: Oleg Guba --- 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))