From f57b4eb46dd35e4360320672c703f9be408e8bc4 Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Fri, 3 Jun 2016 11:08:00 -0700 Subject: [PATCH] mvcc: don't cancel watcher if stream is already closed Close() already cancels all the watchers but doesn't bother to clear out the bookkeeping maps so Cancel() may try to cancel twice. Fixes #5533 --- mvcc/watcher.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mvcc/watcher.go b/mvcc/watcher.go index 5d2f8f71f..9353f8356 100644 --- a/mvcc/watcher.go +++ b/mvcc/watcher.go @@ -117,13 +117,18 @@ func (ws *watchStream) Chan() <-chan WatchResponse { } func (ws *watchStream) Cancel(id WatchID) error { + ws.mu.Lock() cancel, ok := ws.cancels[id] + ok = ok && !ws.closed + if ok { + delete(ws.cancels, id) + delete(ws.watchers, id) + } + ws.mu.Unlock() if !ok { return ErrWatcherNotExist } cancel() - delete(ws.cancels, id) - delete(ws.watchers, id) return nil }