From ab0e92fa75eb6fe09c737137c6caadf1efe93dff Mon Sep 17 00:00:00 2001 From: Gyuho Lee Date: Fri, 22 Dec 2017 14:36:38 -0800 Subject: [PATCH] clientv3: handle non -1 watch ID on cancellation Signed-off-by: Gyuho Lee --- clientv3/watch.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/clientv3/watch.go b/clientv3/watch.go index dbb73f4a21c1..5c6bc8bc14cd 100644 --- a/clientv3/watch.go +++ b/clientv3/watch.go @@ -367,7 +367,8 @@ func (w *watcher) closeStream(wgs *watchGrpcStream) { } func (w *watchGrpcStream) addSubstream(resp *pb.WatchResponse, ws *watcherStream) { - if resp.WatchId == -1 { + // check watch ID for backward compatibility (<= v3.3) + if resp.WatchId == -1 || (resp.Canceled && resp.CancelReason != "") { // failed; no channel close(ws.recvc) return @@ -453,6 +454,7 @@ func (w *watchGrpcStream) run() { // Watch() requested case wreq := <-w.reqc: outc := make(chan WatchResponse, 1) + // TOOD: pass custom watch ID? ws := &watcherStream{ initReq: *wreq, id: -1, @@ -553,6 +555,7 @@ func (w *watchGrpcStream) dispatchEvent(pbresp *pb.WatchResponse) bool { for i, ev := range pbresp.Events { events[i] = (*Event)(ev) } + // TODO: return watch ID? wr := &WatchResponse{ Header: *pbresp.Header, Events: events,