Fix scheduler shrink issue causing I/O orphaned by retired workers#252
Conversation
…ion test Agent-Logs-Url: https://github.com/Coldwings/Elio/sessions/9ff97f4d-e61c-46f4-9c0c-fa7f70605e37 Co-authored-by: Coldwings <11592728+Coldwings@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes a scheduler resize/lifecycle race in runtime::scheduler where shrinking the worker pool could orphan freshly-started async I/O. Previously, a retiring worker's post-running_==false drain phase resumed queued coroutines locally; if such a coroutine started new async I/O (e.g. co_await sleep_for(...)), the operation bound to the retiring worker's io_context, which stops being polled once the thread exits, hanging the coroutine. The fix routes queued tasks back through scheduler_->spawn() when the worker is being retired (scheduler still running) rather than resuming them locally, while preserving local draining during a genuine full shutdown.
Changes:
- In
worker_thread::run(), computeretiring = scheduler_->is_running()and, during the drain phase, respawn queued handles to surviving workers when retiring instead of executing them locally; still destroydonehandles. - Add a targeted regression test that forces a pinned I/O-starting task into a busy retiring worker's inbox and verifies the redistributed I/O completes on the surviving worker.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
include/elio/runtime/scheduler.hpp |
Splits the worker drain phase into a retirement path (respawn queued tasks to active workers) vs. a full-shutdown path (drain locally), preventing orphaned I/O on retiring workers. |
tests/unit/test_scheduler.cpp |
Adds helper tasks and a regression test verifying I/O started by a task queued on a retiring worker completes on a surviving worker after shrink. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.