fix(fetch): keep a cloned request's abort chain alive across GC - #5748
Open
Kjubikstronk wants to merge 1 commit into
Open
fix(fetch): keep a cloned request's abort chain alive across GC#5748Kjubikstronk wants to merge 1 commit into
Kjubikstronk wants to merge 1 commit into
Conversation
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.
Closes #4068.
The abort travels along a chain: the source signal, then this request's controller, then the
clone's controller. Every hop is held only weakly, and
clone()keeps nothing alive, so a GCbetween cloning and aborting breaks the chain and the fetch hangs.
The constructor already guards against exactly this for its own controller:
clone()never did the same, so this applies the same reasoning there.Two hops, not one
Worth recording, because it cost me a wrong first attempt. Retaining only the clone's own
controller is not enough and the repro still hangs: only
ac.signalis handed tofromInnerRequest, and a signal does not keep its controller alive, so that one does needholding, but the request the clone came from is collected too and its controller is what the
source signal's listener derefs. Both have to stay reachable.
Holding the source request rather than just its controller is what makes a clone of a clone
work: each link keeps the next one alive, so intermediates can go out of scope safely.
@andreas-karlsson, this is also why holding the original request did not help you: the clone'sown controller was being collected as well, so the chain was broken at the other end too.
Tests
test/fetch/clone-abort-after-gc.js, in the style of the existing--expose-gctests: one cloneand a chain of three with every intermediate dropped. Both hang until the test times out
without the change.
test/fetch/*.jswith--expose-gc: 468 passed, 5 failed, and the same 5 fail on anunmodified tree.
test/fetch/request.js,test/fetch/abort.js: 35 passed.test/fetch/fetch-leak.js,test/fetch/fire-and-forget.js,test/request-timeout.js: 26 passed.Those are the ones that would notice references being held too long.