Skip to content

fix: prevent premature garbage collection of xhr in fetch polyfill#737

Merged
saghul merged 2 commits intosaghul:masterfrom
jspngh:bugfix/fetch-gc
Jan 12, 2026
Merged

fix: prevent premature garbage collection of xhr in fetch polyfill#737
saghul merged 2 commits intosaghul:masterfrom
jspngh:bugfix/fetch-gc

Conversation

@jspngh
Copy link
Copy Markdown
Contributor

@jspngh jspngh commented Jan 12, 2026

The XMLHttpRequest that is created as part of the fetch call could be prematurely garbage-collected because no strong reference to it exists anymore.

When this happens (garbage collections runs while the fetch is in progress), this leads to a promise that will never resolve.

To fix this, we add a Set that tracks all the active XHR's.

This closes #736

Copy link
Copy Markdown
Owner

@saghul saghul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please commit the result of make js and add the repro test to the tests dir so it's tested going forward.

The `XMLHttpRequest` that is created as part of the `fetch` call
could be prematurely garbage-collected because no strong reference
to it exists anymore.

When this happens (garbage collections runs while the fetch is in
progress), this leads to a promise that will never resolve.

To fix this, we add a `Set` that tracks all the active XHR's.
This is a regression test for the fetch bug
where the XHR object was prematurely garbage-collected.
@saghul saghul merged commit 65e5595 into saghul:master Jan 12, 2026
19 checks passed
@saghul
Copy link
Copy Markdown
Owner

saghul commented Jan 12, 2026

Cheers!

@jspngh jspngh deleted the bugfix/fetch-gc branch January 12, 2026 12:39
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.

Fetch sometimes never resolves

2 participants