Skip to content

fix: snapshot backgroundFetchSize before invoking user code - #410

Open
teamleaderleo wants to merge 1 commit into
isaacs:mainfrom
teamleaderleo:repair/background-fetch-size-source
Open

fix: snapshot backgroundFetchSize before invoking user code#410
teamleaderleo wants to merge 1 commit into
isaacs:mainfrom
teamleaderleo:repair/background-fetch-size-source

Conversation

@teamleaderleo

Copy link
Copy Markdown

Summary

backgroundFetchSize is used to account for a background fetch while its value is still pending.

Unlike normal cache sizes, it currently bypasses the usual size validation. Invalid values such as negative numbers, fractions, NaN, or Infinity can therefore reach the cache's size accounting.

There's also a timing issue when fetchMethod changes backgroundFetchSize synchronously. The current fetch can end up using the new value even though it started with the old one.

This change validates backgroundFetchSize and snapshots it before calling fetchMethod, so each in-flight fetch keeps the size it started with. 0 remains valid, and changes to backgroundFetchSize still apply to later fetches.

Tests

Added coverage for:

  • invalid backgroundFetchSize values;
  • rejecting invalid runtime values without coercing them;
  • mutation from inside fetchMethod;
  • mutations applying to later, but not already-running, fetches;
  • backgroundFetchSize: 0;
  • stale refreshes and caches without size tracking.

Validate backgroundFetchSize and snapshot it before synchronous fetchMethod code can mutate the public field. Keep regression coverage focused on supported public behavior.
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.

1 participant