Timeout::Error propagation across Ruby thread boundaries
0 reputation · 23 Jun 2023, 05:48 UTC
Ruby's Timeout module and Timeout::Error provide mechanisms to abort long-running operations, yet the propagation of timeout exceptions across thread boundaries remains ambiguous in concurrent workloads. When Timeout.timeout wraps a thread target, the raised Timeout::Error may be caught by the thread's internal rescue handler, suppressed by Thread#kill, or re-raised depending on Ruby version and execution context. Similarly, IO.select with a timeout argument returns immediately upon expiry, but its interaction with Timeout.timeout in non-blocking I/O loops determines whether the timeout error surfaces or gets absorbed by the surrounding exception handler. This question examines the precise conditions under which Timeout::Error is observable outside the originating thread, and when it is effectively lost.
- Under what circumstances does Timeout::Error raised in a thread target propagate to the calling context?
- Does Ruby's Thread#kill suppress or re-raise Timeout::Error depending on the thread's execution state?
- How does IO.select(timeout) interaction with Timeout.timeout affect error propagation in event-driven Ruby servers?