There was an initialization race related to validFrom when instantiating a new channel cache, between AddToCache and addChannelCache.
A. AddToCache:
1. If any of the mutation's channels are active in the channel cache map, add entry to the cache
2. Acquire the seqLock, and update highCachedSequence
B. addChannelCache:
1. Acquire the seqLock. Add a new entry to the channel cache map, with validFrom = highCachedSequence + 1
In the case where B1 happens between A1 and A2, the validFrom for the new singleChannelCache will be invalid, as the sequence associated with the mutation being processed is greater than validFrom, but won't be in the cache.
To address, addToCache will need to hold a mutex across A1 and A2. It's preferred to not use seqLock for this, as it will introduce contention with changes processing that needs to retrieve highCachedSequence (independent of changes to the channel cache map). Instead, a new 'validFromLock' can be used. This shouldn't introduce significant contention on the caching side, as addToCache is already single-threaded (inside processEntry).
Build sync_gateway-2.7.0-138 contains sync_gateway commit c582819 with commit message:
CBG-520Add mutex for validFrom handling (#4346)