Skip to content

Commit

Permalink
clientv3: handle non -1 watch ID on cancellation
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
  • Loading branch information
gyuho committed Dec 22, 2017
1 parent c4ca5ad commit ab0e92f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion clientv3/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ab0e92f

Please sign in to comment.