Skip to content

Commit cd0467f

Browse files
authored
[pthreads] Handle exit exceptions during pthread cleanup. (#24711)
Thread cleanup can potentially execute the queue mailbox and trigger an ExitStatus exception, so we must wrap cleanup with callUserCallback to handle the exception or node will complain about an unhandled exception. Fixes #24500, #22490
1 parent 70b0c59 commit cd0467f

7 files changed

+8
-7
lines changed

src/lib/libpthread.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,10 @@ var LibraryPThread = {
251251
} else if (cmd === 'spawnThread') {
252252
spawnThread(d);
253253
} else if (cmd === 'cleanupThread') {
254-
cleanupThread(d.thread);
254+
// cleanupThread needs to be run via callUserCallback since it calls
255+
// back into user code to free thread data. Without this it's possible
256+
// the unwind or ExitStatus exception could escape here.
257+
callUserCallback(() => cleanupThread(d.thread));
255258
#if MAIN_MODULE
256259
} else if (cmd === 'markAsFinished') {
257260
markAsFinished(d.thread);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3735
1+
3745
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7615
1+
7635
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3941
1+
3949
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8046
1+
8066

test/test_core.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9185,7 +9185,6 @@ def test_pthread_create(self):
91859185
self.set_setting('STRICT')
91869186
self.do_core_test('pthread/create.c')
91879187

9188-
@flaky('https://github.com/emscripten-core/emscripten/issues/22617')
91899188
@node_pthreads
91909189
@parameterized({
91919190
'': ([],),

test/test_other.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2151,7 +2151,6 @@ def test(link_flags, lib_suffix):
21512151

21522152
@node_pthreads
21532153
@also_with_modularize
2154-
@flaky('https://github.com/emscripten-core/emscripten/issues/24500')
21552154
def test_dylink_pthread_static_data(self):
21562155
# Test that a side module uses the same static data region for global objects across all threads
21572156

0 commit comments

Comments
 (0)