Skip to main content

Module lifecycle

Module lifecycle 

Source
Expand description

Cooperative cancel and FINALIZE ledger. One-shot lifecycle: INIT → EXECUTE → FINALIZE → EXIT.

§Workload

Coordination (not compute fan-out): one CancellationToken per process invocation. Residual scavenge may use map_cpu when candidate paths are large (see crate::residual). FINALIZE is ordered: Browser.close → residual kill → flush. No multi-writer shared state.

§Graceful shutdown model (rules_rust_encerramento_graceful_shutdown)

This binary is a one-shot CLI, not a daemon. Shutdown is therefore minimal + critical for pipelines, not a full multi-subsystem coordinator:

  1. Detect — OS signals (SIGINT/SIGTERM, Windows Ctrl-C/Break) via crate::browser::shutdown_signal wired inside crate::browser::block_on_browser_timeout.
  2. Signal — cooperative [CancellationToken] cancel (exit 130).
  3. Await / finalize — primary OneShotSession::shutdown (Browser.close + wait ≤5s + kill); residual ledger kill with SIGTERM → grace → SIGKILL; dual stream flush; process ExitCode.

§Deadlines

PhaseBound
Work / navigationCLI --timeout / XDG / step-timeout
Browser.close wait5s (finalize_browser)
Residual child grace (SIGTERM→SIGKILL)[FINALIZE_CHILD_GRACE]
Second OS signalForces residual Lifecycle::finalize immediately

§Not applicable (product law)

Daemon patterns: TaskTracker fleets, readiness probes, SIGHUP hot-reload, sd_notify, PID files, OpenTelemetry flush, TUI terminal restore.

§Safety

On Unix, finalize may send SIGTERM then (after grace) SIGKILL to a recorded Chrome PID as last resort when primary Browser.close reap did not clear the ledger. Profile dirs and Chrome Singleton side-channels are wiped only when recorded in this ledger (never a host-wide chrome wipe).

Structs§

Lifecycle
Runtime token for cooperative cancel and FINALIZE.
ResourceLedger
Ledger of resources owned by this invocation (browser, profile, temp dirs).

Constants§

FINALIZE_CHILD_GRACE
Max wait after residual SIGTERM before escalating to SIGKILL (Unix).

Functions§

current_cancel
Return the cancel token for the active invocation, or a fresh inert token.
current_lifecycle
Return a clone of the active Lifecycle, if one was registered.
kill_unix_gracefulUnix
Send SIGTERM, wait up to grace while the pid exists, then SIGKILL if needed.
mark_profile_dir
Record a temporary Chrome profile directory on the ledger for FINALIZE wipe.
mark_side_channel
Record a side-channel path (SingletonLock, etc.) owned by this launch.