Repository navigation
fix: do not lose a sync fetch result when its signal is already aborted - #437
Open
waw666waw666 wants to merge 1 commit into
Open
waw666waw666 wants to merge 1 commit into
waw666waw666 wants to merge 1 commit into
Conversation
With `ignoreFetchAbort` and `allowStaleOnFetchAbort`, a pre-aborted signal makes the abort handler rebind `res` to call `cb` directly. A synchronous fetchMethod then reaches `cb` while `const p = new Promise(pcall)` is still being constructed, so `cb` reads `p` in its temporal dead zone. The Promise constructor swallows that ReferenceError after the abort path already resolved, the value is never written to the cache, and the key stays attached to the settled background-fetch promise, so later fetch() calls, including forceRefresh, keep returning undefined without calling fetchMethod again. Declare `p` before the callbacks, and if `cb` runs before `p` exists, defer it a microtask, when `p` does exist. The asynchronous path is unchanged: `cb` still runs synchronously once `p` exists, and the first fetch still resolves to undefined, as it does for an asynchronous fetchMethod. Fixes isaacs#436.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
With
ignoreFetchAbortandallowStaleOnFetchAbort, a pre-abortedsignal makes the abort handler rebind
resto callcbdirectly.A synchronous fetchMethod then reaches
cbwhileconst p = new Promise(pcall)is still being constructed, socbreads
pin its temporal dead zone. The Promise constructor swallowsthat ReferenceError after the abort path already resolved, the value
is never written to the cache, and the key stays attached to the
settled background-fetch promise, so later fetch() calls, including
forceRefresh, keep returning undefined without calling fetchMethod
again.
Declare
pbefore the callbacks, and ifcbruns beforepexists, defer it a microtask, when
pdoes exist. The asynchronouspath is unchanged:
cbstill runs synchronously oncepexists,and the first fetch still resolves to undefined, as it does for an
asynchronous fetchMethod.
Fixes #436.
Testing:
test/fetch.test.ts29/29;test/tracing.test.ts+test/fetch.test.ts122/122; the only stable failure in the full suite on this machine is the pre-existingmax above 2**16timeout, which fails on the baseline too and is unrelated to this change.