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
This commit is contained in:
Anthony Romano 2016-06-03 11:08:00 -07:00
parent b3fee0abff
commit f57b4eb46d

View File

@ -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
}