Skip to content

Commit f14aa9b

Browse files
committed
Allow late print calls from terminating pthreads
When a pthreaded application exits under PROXY_TO_PTHREAD and EXIT_RUNTIME, the worker thread signals the main thread to exit using the system queue. However, there can also be messages from postMessage in-flight from the worker. This results in a race condition where the main thread processes the exit and terminates the worker (synchronously stubbing out its onmessage handler to discard further messages) before processing print messages already posted by the worker before exiting. As a result, valid printed output is lost, and the test fails due to unexpected assertion warnings. Resolve this by allowing messages after termination. Fixes flaky test test_pthread_print_override_modularize. Fixes #19683
1 parent 999496e commit f14aa9b

2 files changed

Lines changed: 0 additions & 15 deletions

File tree

src/lib/libpthread.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -591,17 +591,6 @@ var LibraryPThread = {
591591
dbg(`terminateWorker: ${worker.workerID}`);
592592
#endif
593593
worker.terminate();
594-
// terminate() can be asynchronous, so in theory the worker can continue
595-
// to run for some amount of time after termination. However from our POV
596-
// the worker is now dead and we don't want to hear from it again, so we stub
597-
// out its message handler here. This avoids having to check in each of
598-
// the onmessage handlers if the message was coming from a valid worker.
599-
worker.onmessage = (e) => {
600-
#if ASSERTIONS
601-
var cmd = e.data.cmd;
602-
err(`received "${cmd}" command from terminated worker: ${worker.workerID}`);
603-
#endif
604-
};
605594
},
606595

607596
_emscripten_thread_cleanup: (thread) => {

test/test_other.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6166,10 +6166,6 @@ def test_modularize_instantiation_error(self):
61666166

61676167
@crossplatform
61686168
@requires_pthreads
6169-
@flaky('https://github.com/emscripten-core/emscripten/issues/19683')
6170-
# The flakiness of this test is very high on macOS so just disable it
6171-
# completely.
6172-
@no_mac('https://github.com/emscripten-core/emscripten/issues/19683')
61736169
def test_pthread_print_override_modularize(self):
61746170
self.set_setting('EXPORT_NAME', 'Test')
61756171
self.set_setting('PROXY_TO_PTHREAD')

0 commit comments

Comments
 (0)