Problem/Motivation
#3438424: [random test failures] Race condition in state when individual keys are set with an empty cache attempted to fix a race condition with the State
usage of CacheCollector
by setting a cache item immediately after setting a new state value, so that requests that started with an empty cache wouldn't write to cache at the end at the end of the request, potentially writing back a cache item for the old state value before it was set.
This worked most of the time, but not in the case that the request that was attempting to set the new value failed to acquire the cache write lock in ::updateCache() (e.g. when another request was just writing to cache).
For this case, we want to write to the cache even if the lock can't be acquired, since our new value takes precedence over whatever's being written in the other request.
Steps to reproduce
Proposed resolution
Directly attempt to acquire the lock in State::set(), and write the cache whether or not the lock is acquired.
Additionally, run the cache invaidation logic in CacheCollector::updateCache() even if the lock isn't acquired, only cache sets are constrained by acquiring the lock now.