Let WnWrap release shared calls after Alarmmgr exits
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user