Skip to main content

clear_active_pid_if_pid

Function clear_active_pid_if_pid 

Source
pub fn clear_active_pid_if_pid(
    mstore: &Arc<Store>,
    block_id: &str,
    expected_pid: u32,
)
Expand description

Clear session:active_pid only if it still equals expected_pid — a transactional compare-and-clear for exit-handlers that know which process instance they are cleaning up after.

Issue #2363: PersistentSubprocessController’s fallback respawn (respawn_once_for_leftover_queue) runs on a separate tokio task from the dying process’s own exit-handler. The exit-handler’s cleanup is gated on a spawn-generation check, but that gate is read once under the controller’s lock while the fallback registers its own fresh PID in parallel — the unconditional clear_active_pid could then wipe the NEW process’s registration, leaving it untracked for crash recovery until the next natural re-registration. The whole read-compare-clear here runs inside one Store::with_tx (a single connection lock across read+merge+write — see object_helpers::update_object_meta’s doc comment for the transactional contract), so a concurrent mark_active_pid strictly serializes against it: whichever commits second sees the other’s completed write, and a mismatch means “a newer process already registered — leave it alone.”

Best-effort like the unconditional variant: logs on failure, never panics. Returns nothing — callers do not branch on the outcome.