Repository navigation
Conversation
Replace manual scheduler and I/O driver host cleanup pairs with RAII guards so partial construction and unwinding release worker-local resources in the existing teardown order. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the guard-based worker cleanup changes.
No open issues 🎉
What changed in this PR
This PR replaces manual worker-local cleanup in Arty with private guards that release the scheduler context and I/O driver host when dropped. It preserves normal shutdown order while adding cleanup during partial construction and unwinding.
Changes:
- Store cleanup guards in the asynchronous worker state.
- Pass the I/O driver-host guard from thread setup into the worker.
- Add tests for guard-based cleanup and unwinding.
| File | Description |
|---|---|
crates/arty/src/runtime/worker/asynchronous/worker.rs |
Owns both guards and drops them in the existing shutdown order. |
crates/arty/src/runtime/worker/asynchronous/thread.rs |
Transfers the installed driver-host guard into the worker. |
crates/arty/src/runtime/worker/asynchronous/local_worker.rs |
Adds scheduler cleanup on guard drop and an unwinding test. |
crates/arty/src/io/mod.rs |
Re-exports the driver-host guard internally. |
crates/arty/src/io/driver_host.rs |
Returns a cleanup guard from installation and tests drop and unwind behavior. |
Review effort: Balanced
| } | ||
|
|
||
| impl Drop for InstalledDriverHost { | ||
| fn drop(&mut self) { |
|
|
||
| pub(super) fn clear_scheduler() { | ||
| let scheduler = Self::with_current_mut(|current| current.and_then(|current| current.scheduler.take())); | ||
| fn clear_scheduler() { |
| .take() | ||
| .expect("the task worker must uninstall the I/O driver host that it installed") | ||
| }) | ||
| pub(crate) fn take_driver_host() -> Option<RuntimeDriverHost> { |
| pub(super) struct SchedulerGuard; | ||
|
|
||
| impl Drop for SchedulerGuard { | ||
| fn drop(&mut self) { |
|
|
||
| impl Drop for SchedulerGuard { | ||
| fn drop(&mut self) { | ||
| LocalWorker::clear_scheduler(); |
| let driver_waker = RuntimeDriverHost::install(&io_runtime, dispatcher.clone(), ¤t, asynchronous::Signal::waker(&signal)); | ||
| signal.set_driver_waker(driver_waker); | ||
| let driver_host = RuntimeDriverHost::install(&io_runtime, dispatcher.clone(), ¤t, asynchronous::Signal::waker(&signal)); | ||
| signal.set_driver_waker(driver_host.waker()); |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #982 +/- ##
==========================================
Coverage 100.0% 100.0%
==========================================
Files 798 116 -682
Lines 68902 7210 -61692
==========================================
- Hits 68902 7210 -61692
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
martintmk
marked this pull request as draft
November 13, 2026 08:16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Arty stored the asynchronous scheduler context and I/O driver host in worker-local storage. Their lifetimes depended on matching manual clear and uninstall calls. This change returns private RAII guards from both install operations and keeps them in the worker state.
The guards preserve the existing shutdown order. They also remove each resource during partial construction or unwinding, before thread-local destruction. The worker marker and blocking worker identity still remain attached through thread teardown because thread-local destructors depend on that behavior.
arty_executoralready uses guards for cycle state and executor unregistration, so this change does not alter it.Focused validation passed with
cargo test -p arty --lib unwinding_ --no-fail-fast. Package validation passed withcargo check -p arty.