From ca4acceb1e3cd2f9986d9a7f542ee2a4ca61ceaa Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Sat, 22 Apr 2017 12:53:03 -0700 Subject: [PATCH] clientv3: set current revision to create rev regardless of CreateNotify Turns out the optimization to ignore setting the init rev for current revision watches breaks some ordering assumptions. Since Watch only returns a channel once it gets a response, it should bind the revision at the time of the first create response. Was causing TestWatchReconnInit to fail. --- clientv3/watch.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/clientv3/watch.go b/clientv3/watch.go index d85f3686d..b78a79522 100644 --- a/clientv3/watch.go +++ b/clientv3/watch.go @@ -615,13 +615,18 @@ func (w *watchGrpcStream) serveSubstream(ws *watcherStream, resumec chan struct{ // send first creation event only if requested if ws.initReq.createdNotify { ws.outc <- *wr - if ws.initReq.rev == 0 { - // current revision of store; returning the - // create response binds the current revision to - // this revision, so restart with it if there's a - // disconnect before receiving any events. - nextRev = wr.Header.Revision - } + } + // once the watch channel is returned, a current revision + // watch must resume at the store revision. This is necessary + // for the following case to work as expected: + // wch := m1.Watch("a") + // m2.Put("a", "b") + // <-wch + // If the revision is only bound on the first observed event, + // if wch is disconnected before the Put is issued, then reconnects + // after it is committed, it'll miss the Put. + if ws.initReq.rev == 0 { + nextRev = wr.Header.Revision } } } else {