In CouchbaseBucketGoCB's Incr method, when the amount specified to increment by is zero, we have special handling in place to instead do a normal Get op, in order to work around some GoCB-specific counter handling.
This logic is sound in the case when err is ErrKeyNotFound, but under other circumstances, in the case where Get's retry loop aborts with an error, this logic is incorrect, and allows the Incr op to report an incorrect counter value of zero.
In Sync Gateway 1.5.2, this manifests when the Couchbase Server node containing the _sync:seq doc is down and not failedover (the Get op persistently times out for each retry). Swallowing an ErrTimeout means SG happily continues to start up thinking it has a starting sequence of zero.
We instead should explicitly check for ErrKeyNotFound in the special-handling code above when returning "0, nil". for any other errors we "0, err".
This should be easy enough to test in an integration test with LeakyBucket by forcing a timeout error on a Get() op when calling Incr() with amt=0.