Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(graphcache): Prevent refetch cycles when handling cache misses #2737

Merged
merged 2 commits into from
Oct 14, 2022

Conversation

kitten
Copy link
Member

@kitten kitten commented Oct 13, 2022

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:

  • Are cache-miss cycles always transitive? In other words, can a cycle take a longer path than two operations?
  • Are there any valid cases where two operations are now unable to updated in sequence? This must at all costs be prevented. There could be sequences of two operations updating in sequence that must then re-trigger a cache read for the first

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

  • Introduce double-set tracking to prevent operation re-execution cycles

@changeset-bot
Copy link

changeset-bot bot commented Oct 13, 2022

🦋 Changeset detected

Latest commit: f5a38e0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@urql/exchange-graphcache Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@kitten kitten changed the title fix(graphcache): Prevent infinite loops when handling cache misses fix(graphcache): Prevent refetch cycles when handling cache misses Oct 13, 2022
@kitten kitten force-pushed the fix/graphcache-disallow-infinite-loops branch from eec46e0 to e9cb816 Compare October 14, 2022 09:16
@kitten kitten force-pushed the fix/graphcache-disallow-infinite-loops branch from e9cb816 to 97f7f3d Compare October 14, 2022 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants