make possibly conflicting optimistic cache updates write to each other #1772
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
My theory as to why #1655 and #1669 occur is that an earlier and conflicting optimistic mutation fails while another optimistic mutation is in progress. When the optimistic mutation fails, it rolls back the cache to its initial state which causes the in-progress optimistic mutation to have its cache updates overwritten.
In the case of #1655, I believe that this occurs when an earlier zap (in a succession of zaps) fails. In the case of #1669, I believe this occurs when a poll is zapped, then voted on.
I've made the relevant cache updates write to each other. It's very hard to reproduce so I'm not sure I got all the relevant
cache.modify
calls, but I'll continue looking for any cache updates on the optimistic response path in the few places we do it (zaps/boosts/polls) ... it's unclear if there are consequences to doing it on everycache.modify
call.Update: I've made all the
cache.modify
calls on items update optimistic caches. This might be unnecessary overhead but afaict it shouldn't cause anything bad to happen, and should prevent optimistic rollbacks from affecting these cache updates.