mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
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:
parent
b3fee0abff
commit
f57b4eb46d
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user