Skip to content

Fix flakiness in test_itimer_proxy_to_pthread - #27789

Merged
sbc100 merged 1 commit into
emscripten-core:mainfrom
sbc100:fix_flake
Sep 28, 2026
Merged

sbc100 merged 1 commit into
emscripten-core:mainfrom
sbc100:fix_flake

Conversation

@sbc100

@sbc100 sbc100 commented Sep 27, 2026 •

Copy link
Copy Markdown
Collaborator

Followup to #27778.

Calling printf in these signal handlers was causing issues since it requires taking the stdio lock which in turn can run more proxied work (signal handler all run on the main thread). In this case, the flake is caused by the setitimer which cancels the timers running during the printf call (and before the counter is incremented), i.e. in the middle of the signal handler. This means that worker thread can observe the effect of the timer (the counter being incremented) after the timer is cancelled (because the cancellation effectively ran during the execution of the signal handler).

Possible followups to avoid this type of thing in the future:

  1. Mask signals during handler (This is the default, but we don't implement it yet in emscirpten, it prevents the timer signal running before the previous one has finished).
  2. Don't run proxied work during a signal handler. Signal handler should always be fast so the main thread should be able to delay running any proxied work until the end of a given signal handler.

Fixes: #20125

Calling `printf` in these signal handlers was causing issues since it
requires taking the stdio lock which in turn can run more proxied work
(signal handler all run on the main thread).

Fixes: emscripten-core#20125
@sbc100
sbc100 merged commit e3fb447 into emscripten-core:main Sep 28, 2026
42 checks passed
@sbc100
sbc100 deleted the fix_flake branch September 28, 2026 18:58
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.

test_itimer is flaky on macOS

2 participants