fn SweepStaleCocoon(Port: u16)Expand description
Atom I6: pre-boot sweep. TCP-probe the Cocoon gRPC port and kill any stale process still bound to it. Prevents the EADDRINUSE cascade that leaves the extension host in degraded mode when a prior Mountain exited without cleaning up its child.
Behaviour:
- If the port answers a TCP connect, assume an owner is listening.
- Use
lsof -nP -iTCP:<port> -sTCP:LISTEN -t(macOS/Linux) to resolve the PID.lsofis ubiquitous on macOS/Linux and doesn’t require root for local user-owned processes. - SIGTERM first, 500ms grace window, then SIGKILL if still alive.
- Logs every step via
dev_log!("cocoon", …)so the sweep is visible in Mountain.dev.log without parsing stderr. - Best-effort: failures don’t abort Mountain boot. A real EADDRINUSE later will surface via Cocoon’s own bootstrap error.