Skip to content

Conversation

@juj
Copy link
Collaborator

@juj juj commented Dec 11, 2025

Fix browser.test_fetch_stream_abort_asan race condition by avoiding double free of the fetch structure.

The issue in the test was that onprogress handler in the test would queue a setimmediate to free the fetch structure after the turn of the event loop.

But the browser might also have fed a second onprogress handler call before the previous setimmediate, which would also trigger a second setimmediate callback.

Then the two setimmediate callbacks would fire, resulting in a double emscripten_fetch_close() calls, and the asan test croaking:

image

Fix the race condition by ensuring only a single abort is queued.

@juj juj force-pushed the fix_test_fetch_stream_abort branch from e043f3e to 3ddc3e7 Compare December 11, 2025 01:02
fetch->dataOffset + fetch->numBytes);

if (fetch_abort_queued) return;
fetch_abort_queued = true;
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about:

if (!fetch_abort_queued) {
   fetch_abort_queued = true;
   emscripten_set_immediate([](void *arg) {
      ...
   }
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure that changes anything for the better - deeper nesting and testing for negation.

@juj juj merged commit daa0f55 into emscripten-core:main Dec 11, 2025
34 of 35 checks passed
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