You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think this is indeed possible to get a stale value:
Thread A | Thread B | Thread C
----------------------------------------------------------------------------------------------------------------------------------------------
ENTER invalidate(42)
invalidations ++
change remote state
ENTER invalidate(42)
invalidations ++
ENTER get(42, loader)
i = invalidations
t = tokens.computeIfAbsent(42, -> new) // old
t = tokens.remove(42) // found
val = dataCache.get(t, loader) // from cache
t = tokens.remove(42) // not found
EXIT invalidate(42)
if i == invalidations // true
tokens.putIfAbsent(42, t) // "Revive"
ENTER get(42, loader)
t = tokens.computeIfAbsent(42, -> new) // old
val = dataCache.get(t, loader) // from cache
return val // ‼️ old value returned despite explicit invalidation
EXIT get(42, loader)
if !dataCache.containsKey(t) // false
return val
EXIT get(42, loader)
dataCache.invalidate(t) // this fixes the temporarily incorrect state
EXIT invalidate(42)
Indeed, if i revert the "Revive" code (17faae3), i can no longer reproduce the problem
findepi
changed the title
EvictableCache race condition
EvictableCache race condition can temporarily revive old entry
Jun 5, 2024
TestEvictableLoadingCache.testInvalidateAndLoadConcurrently
was found to be flaky (with probability ~0.000003 on my local machine).found by @anusudarsan
The text was updated successfully, but these errors were encountered: