fix(graphcache): Prevent refetch cycles when handling cache misses #2737
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.
NOTE: This fix isn't fully verified yet and the code needs to be verified to not break any existing behaviour.
Summary
See prior approach in #2731.
When an operation is read from the cache, if we encounter a cache miss then a network request is sent, which subsequently updates the cache.
However, suppose an operation has several dependencies on the cache-missed operation. If any of the dependent operations then also experience a cache-miss, this will then subsequently retrigger the original operation as well. This is because any dependencies between operations will always be bi-directional by definition.
The easiest approach to solve this issue is to prevent direct cycles, meaning, if an operation triggers another, then we disallow the subsequent operation to trigger the first again, hence breaking infinite cycles.
As per the note at the top of this PR, while this is the minimum solution, we haven't verified two things, due to this being hard for us to test for currently:
At least the second statement above is guaranteed and verified by only applying this restriction to
cacheMissOps$
, i.e. the stream of operations after it has tried to read from the cache, experienced a cache miss, and are about to be forwarded.Set of changes