Details
-
Bug
-
Resolution: Fixed
-
Major
-
2.0.0
-
Security Level: Public
-
CBG Sprint 21
-
3
Description
Background
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.
Example error scenario
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.
Proposed fix
We instead should explicitly check for ErrKeyNotFound in the special-handling code above when returning "0, nil". for any other errors we "0, err".
Testing
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.
Attachments
Issue Links
- backports to
-
CBG-432 Backport CBG-342 to 2.5.1 (GoCB Bucket Incr amt=0 logic not handling errors correctly)
- Closed