From 8fe50f7cadc2baab521a03225f698b953416546d Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Sat, 21 Nov 2026 14:46:51 -0500 Subject: [PATCH] Let WnWrap release shared calls after Alarmmgr exits --- src/mxgateway-worker-rust/src/alarm.rs | 9 ++++++++- .../src/alarm/snapshot_worker.rs | 15 +++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/mxgateway-worker-rust/src/alarm.rs b/src/mxgateway-worker-rust/src/alarm.rs index b8948816..97e2e28c 100644 --- a/src/mxgateway-worker-rust/src/alarm.rs +++ b/src/mxgateway-worker-rust/src/alarm.rs @@ -117,7 +117,14 @@ impl Primary { self.require_live_query |= manager_exited; if manager_exited || (emit && manager_missing) { let lost_source = self.source.is_some(); - self.reset(); + if manager_exited { + self.pending_until = None; + if let Some(source) = self.source.take() { + source.finish_after_manager_exit(); + } + } else { + self.reset(); + } return (may_request || lost_source) .then_some(Err((0x8007_0000 | ERROR_SERVICE_NOT_ACTIVE) as HRESULT)); } diff --git a/src/mxgateway-worker-rust/src/alarm/snapshot_worker.rs b/src/mxgateway-worker-rust/src/alarm/snapshot_worker.rs index 9c0a7bd4..4e973f3e 100644 --- a/src/mxgateway-worker-rust/src/alarm/snapshot_worker.rs +++ b/src/mxgateway-worker-rust/src/alarm/snapshot_worker.rs @@ -75,6 +75,17 @@ impl SnapshotProcess { } pub fn finish(self) { + self.finish_with_grace(2_000); + } + + pub fn finish_after_manager_exit(self) { + // AlarmBuf waits five seconds for a reply before it checks whether + // Alarmmgr exited. Let it release its shared call mutex before killing + // the helper. The parent stops reading this helper as soon as it retires. + self.finish_with_grace(7_000); + } + + fn finish_with_grace(self, grace_ms: u32) { let Self { job, child, @@ -82,13 +93,13 @@ impl SnapshotProcess { replies: _, } = self; drop(requests); - // Give an idle helper time to deregister. A COM teardown that stalls + // Give the helper time to deregister. A COM teardown that stalls // cannot delay UnsubscribeAlarms or keep the job alive indefinitely. let _ = thread::Builder::new() .name("wnwrap-snapshot-cleanup".into()) .spawn(move || { // SAFETY: the child process handle is owned by this thread. - unsafe { WaitForSingleObject(child.as_raw_handle(), 2_000) }; + unsafe { WaitForSingleObject(child.as_raw_handle(), grace_ms) }; drop(job); }); }