Skip to content

fix(arty): guard worker-local cleanup - #982

Draft
martintmk wants to merge 1 commit into
mainfrom
martintmk-local-lifetime-guards
Draft

martintmk wants to merge 1 commit into
mainfrom
martintmk-local-lifetime-guards

Conversation

@martintmk

Copy link
Copy Markdown
Member

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_executor already 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 with cargo check -p arty.

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>
Copilot AI balanced review requested due to automatic review settings November 13, 2026 07:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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(), &current, asynchronous::Signal::waker(&signal));
signal.set_driver_waker(driver_waker);
let driver_host = RuntimeDriverHost::install(&io_runtime, dispatcher.clone(), &current, asynchronous::Signal::waker(&signal));
signal.set_driver_waker(driver_host.waker());
@codecov

codecov Bot commented Nov 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.0%. Comparing base (ff31146) to head (f68c9e8).
⚠️ Report is 7 commits behind head on main.

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     
Flag Coverage Δ
linux 100.0% <100.0%> (ø)
linux-arm 100.0% <100.0%> (ø)
scheduled ?
windows 100.0% <100.0%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@martintmk
martintmk marked this pull request as draft November 13, 2026 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants