Skip to content

Do not throw from TUring::Wait on EINTR - #224

Merged
resetius merged 1 commit into
masterfrom
fix-217-uring-eintr
Nov 19, 2026
Merged

resetius merged 1 commit into
masterfrom
fix-217-uring-eintr

Conversation

@resetius

Copy link
Copy Markdown
Owner

Fixes #217

TUring::Wait() threw when io_uring_enter returned -EINTR, so any signal (e.g. a gdb attach) killed the event loop. Now -EINTR is treated as a wake-up, the same as in the epoll backend (which returns early on EINTR): completions and timers are processed and the caller loops. Other errors still throw.

Test: test_uring_wait_signal interrupts a blocked Wait({5,0}) with SIGUSR1 (no SA_RESTART) from another thread. It throws Interrupted system call without the fix and passes with it (rpi5, full ut_tests: 276 passed).

Treat -EINTR from io_uring_enter as a wake-up, like the epoll backend does, so signals (e.g. gdb attach) no longer kill the event loop.
@github-actions

Copy link
Copy Markdown

Unit Test Results (MacOS)

254 tests  ±0   254 ✅ ±0   27s ⏱️ -5s
  4 suites ±0     0 💤 ±0 
  4 files   ±0     0 ❌ ±0 

Results for commit 6bfe2fd. ± Comparison against base commit 85489f0.

@github-actions

Copy link
Copy Markdown

Unit Test Results (Linux)

334 tests  +1   334 ✅ +1   24s ⏱️ -1s
  4 suites ±0     0 💤 ±0 
  4 files   ±0     0 ❌ ±0 

Results for commit 6bfe2fd. ± Comparison against base commit 85489f0.

@github-actions

Copy link
Copy Markdown

Unit Test Results (Windows)

175 tests  ±0   175 ✅ ±0   43s ⏱️ -1s
  4 suites ±0     0 💤 ±0 
  4 files   ±0     0 ❌ ±0 

Results for commit 6bfe2fd. ± Comparison against base commit 85489f0.

@resetius

Copy link
Copy Markdown
Owner Author

Independent review of head 6bfe2fd6c3a41e0d9cbad25fee21ab252e835208. Verdict: the fix is correct. No P1/P2 findings, one P3 note.

What I checked

  • TUring::Wait() throws on EINTR from io_uring_enter, so any signal (e.g. gdb attach) kills the loop #217 and the diff (coroio/backends/uring.cpp:273-274).
  • No lost submissions on EINTR. io_uring_enter submits SQEs before it waits. If it submitted any, it returns that count rather than -EINTR, and liburing passes the count through. So -EINTR means there was nothing left to submit, and the closes PrepClose queued just before are not lost.
  • Signal and timeout semantics compared with the other backends. With the PR, Wait() goes on to the CQE loop and ProcessTimers(). CQEs already posted and timers already due are handled in the same iteration. epoll returns before ProcessTimers() (epoll.cpp:147-149). Either way the next Step() recomputes the timeout, which is capped at 100 ms. Other errors still throw. Cancel(TOperation&) already retried on EINTR. IOCP is not affected: GetQueuedCompletionStatusEx is called non-alertable.
  • The test fails without the fix. On rpi5 (Linux 7.3, liburing 2.15) with master's uring.cpp, it aborts with terminate ... io_uring_wait_cqe_timeout: Interrupted system call. With the fix it passed 5 out of 5 runs.
  • Stress run, local only and not part of the PR. A TLoop<TUring> sent 64 MB over TCP loopback and checked the byte pattern, while doing 20 sleeps of 50 ms. Meanwhile another thread sent SIGUSR1 (no SA_RESTART) every 200 µs, about 4.5k signals in total. On this head all bytes arrived intact and no timer fired early, in 3 out of 3 runs. On master it throws at the first signal that lands in the wait.
  • Full ctest with ASan on rpi5: all passed (tests 276/276). The change is Linux-only. CI: every job on this head is green.

Findings

  • P3: tests/tests.cpp:1456 and :1463. The test assumes the loop thread is already inside io_uring_enter 100 ms after the helper thread starts. On a slow or loaded runner the signal could arrive before Wait() starts. Then Wait({5, 0}) blocks for the full 5 s, returns 0, and the < 4 s assertion fails. This is unlikely. Re-sending the signal until Wait() returns (an atomic flag) would remove the timing dependence.
  • Out of scope, worth a separate issue. TUring::Wait() throws on EINTR from io_uring_enter, so any signal (e.g. gdb attach) kills the loop #217 says the epoll and kqueue backends handle EINTR, but only epoll does. On master, kqueue (kqueue.cpp:108), poll (poll.cpp:121) and select (select.cpp:74) still throw. I installed a SIGUSR1 handler without SA_RESTART and sent the signal during Step(). The results were kevent: Interrupted system call (macOS), poll: Interrupted system call (macOS and Linux) and select: Interrupted system call (macOS and Linux). On Linux, poll and select are never restarted after a handler, even with SA_RESTART.

@resetius resetius added the agent-reviewed An independent review agent checked this PR; the verdict is in a PR comment label Nov 19, 2026
@resetius
resetius merged commit b559459 into master Nov 19, 2026
7 checks passed
@resetius
resetius deleted the fix-217-uring-eintr branch November 19, 2026 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-reviewed An independent review agent checked this PR; the verdict is in a PR comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUring::Wait() throws on EINTR from io_uring_enter, so any signal (e.g. gdb attach) kills the loop

1 participant