Crystal fiber cancellation limits under cooperative scheduling
0 reputation · 02 Dec 2021, 19:23 UTC
Designing graceful cancellation and timeouts for long-running work in Crystal requires understanding the documented limits of fiber cooperation and select-based waiting.
Fibers are cooperative and scheduled by the runtime. Cancellation does not preempt a running fiber; a fiber must reach a yield point to observe a cancellation signal. Timeouts are typically expressed via select with a timeout branch or timed waits, and there is no universal wrapper that automatically aborts arbitrary blocking code. Cancellation and timeout handling do not automatically propagate to child fibers or clean up held resources, so explicit protocols are needed.
For a design that relies on cooperative cancellation, the boundaries of documented behavior are not fully clear.
What documented mechanism exists for cooperative cancellation signaling between parent and child fibers? Under what conditions does a select timeout branch guarantee observation before a blocking IO completes? Is timeout accuracy documented when a fiber remains blocked in kernel IO until the next yield?