Skip to content

Commit daa0f55

Browse files
authored
Fix browser.test_fetch_stream_abort_asan race condition (#25931)
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: <img width="1361" height="1352" alt="image" src="https://github.com/user-attachments/assets/067491b5-0093-4072-98a6-aa02911e3693" /> Fix the race condition by ensuring only a single abort is queued.
1 parent e7706b3 commit daa0f55

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

test/fetch/test_fetch_stream_abort.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <emscripten/fetch.h>
1212
#include <emscripten/eventloop.h>
1313

14+
bool fetch_abort_queued = false;
15+
1416
int main() {
1517
emscripten_fetch_attr_t attr;
1618
emscripten_fetch_attr_init(&attr);
@@ -32,6 +34,8 @@ int main() {
3234
fetch->dataOffset,
3335
fetch->dataOffset + fetch->numBytes);
3436

37+
if (fetch_abort_queued) return;
38+
fetch_abort_queued = true;
3539
emscripten_set_immediate([](void *arg) {
3640
emscripten_fetch_t *fetch = (emscripten_fetch_t *)arg;
3741
printf("Abort fetch when downloading\n");

0 commit comments

Comments
 (0)