You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test_pthread_run_on_main_thread seems to be causing chrome to stop responding #18210
Not consistently, but I was seeing it fail more often than not in the last day or so. For example, I saw it fail 4 or 5 times in a row on a single PR, and at the same time file across 5 separate PRs, but at the same time of those PRs did eventually land.
I was trying to make this test pass under node and I found the cause of the deadlock. The following simple program wil consistently reproduce the issue under node:
#include <emscripten/threading.h>
#include <stdio.h>
#include <assert.h>
#include <math.h>
void v() {
assert(emscripten_is_main_runtime_thread());
printf("Hello!\n");
}
void *thread_main(void*) {
// Make the main thread call printf
emscripten_async_run_in_main_runtime_thread(EM_FUNC_SIG_V, v);
// Now call printf outselves.
printf("never see this\n");
return 0;
}
int main() {
pthread_t thread;
int rc = pthread_create(&thread, NULL, thread_main, NULL);
assert(rc == 0);
rc = pthread_join(thread, 0);
assert(rc == 0);
return 0;
}
The problem comes down to this:
main thread spawns worker thread and then blocked until its done
main thread "blocks" by waking up ever 1ms to check for tasks
worker thread sends v as an async task for main thread
before main thread wakes up, worker thread calls printf which essentially does:
acquires stdout lock
syncronously proxy fd_write syscall to main thread (worker thread never returns from this)
release stdout lock
main thread wakes up and starts performing its first task which is v
main thread calls printf as part of running v
main thread attempt to acquire the printf lock of the worker thread is holding it.
main thread waits forever, and does not perform any more tasks because we don't run tasks recursively
@tlively and I discussed the issue but cannot find a reasonable fix. For now I think I will re-enable the test but use -sPROXY_TO_PTHREAD to avoid the deadlock.
Activity
Temporarily disable test_pthread_run_on_main_thread under chrome
Temporarily disable test_pthread_run_on_main_thread under chrome (#18211
kripken commentedon Nov 16, 2022
Does it fail consistently, or randomly?
sbc100 commentedon Nov 16, 2022
Not consistently, but I was seeing it fail more often than not in the last day or so. For example, I saw it fail 4 or 5 times in a row on a single PR, and at the same time file across 5 separate PRs, but at the same time of those PRs did eventually land.
sbc100 commentedon Dec 3, 2022
Seems like maybe this was effecting firefox too: #18307
sbc100 commentedon Feb 8, 2024
I was trying to make this test pass under node and I found the cause of the deadlock. The following simple program wil consistently reproduce the issue under node:
The problem comes down to this:
vas an async task for main threadprintfwhich essentially does:vprintfas part of runningvsbc100 commentedon Feb 8, 2024
@tlively and I discussed the issue but cannot find a reasonable fix. For now I think I will re-enable the test but use
-sPROXY_TO_PTHREADto avoid the deadlock.sbc100 commentedon Feb 8, 2024
Actually
PROXY_TO_PTHREADdoesn't make any difference. Replacingprintfwithemscripten_outfworks around it though.Fix around deadlock in test_pthread_run_on_main_thread
Fix around deadlock in test_pthread_run_on_main_thread
Fix around deadlock in test_pthread_run_on_main_thread
Fix deadlock in test_pthread_run_on_main_thread
Fix deadlock in test_pthread_run_on_main_thread
Fix deadlock in test_pthread_run_on_main_thread
Fix deadlock in test_pthread_run_on_main_thread (#21296)
Fix deadlock in test_pthread_run_on_main_thread (emscripten-core#21296)
Merge upstream 3.1.56 (#64)