Skip to content

fix(supervisor): prune stale tombstones on TID collision and shutdown socket errors - #16176

Closed
Liang-Psych wants to merge 1 commit into
posit-dev:mainfrom
Liang-Psych:fix/16167-supervisor-tombstones
Closed

Liang-Psych wants to merge 1 commit into
posit-dev:mainfrom
Liang-Psych:fix/16167-supervisor-tombstones

Conversation

@Liang-Psych

Copy link
Copy Markdown
Contributor

Fixes #16167.

Root cause (verified in a Linux Docker deployment)

Two defects combine into permanent tombstones:

  1. isProcessAlive uses kill(pid, 0). On Linux, thread IDs share the PID number space, so it succeeds for a worker thread (e.g. tokio-rt-worker) that recycled a dead supervisor's PID — auto-prune is skipped.
  2. handleShutdownAction calls removeByPid only on the success path. When the socket is already gone (ENOENT), execution jumps to catch, the entry is never removed, and Shut Down always fails the same way.

Worst case: a supervisor killed with kill -9/OOM never unlinks its socket, so both existsSync and kill(pid, 0) return true simultaneously.

Changes (extensions/positron-supervisor)

  • showRunningSupervisors now prunes via new isSupervisorAlive(pid, socketPath): kill(pid, 0) + socket must exist + on Linux only, /proc/<pid>/comm must be kcserver (zero-dependency, pidfd_open would need native bindings).
  • handleShutdownAction drops the registry entry when shutdown fails with ENOENT/ECONNREFUSED (conservative: timeouts on live supervisors still keep the entry).
  • New src/test/supervisorLiveness.test.ts (4 cases) for the existing harness.

Verification

  • tsc --noEmit clean on the extension; eslint not runnable in this sandbox (no local binary, registry blocked) — CI lint will cover it.
  • /proc comm behavior verified empirically in a CentOS 7 container: worker thread reads as tokio-rt-worker, live supervisor as kcserver.

… socket errors

On Linux, thread IDs share the PID number space, so kill(pid, 0) can
succeed for a worker thread that recycled a dead supervisor's PID,
while a crashed supervisor may never unlink its socket. Both facts
together blind the pruning logic and leave permanent tombstones.

- showRunningSupervisors now requires the socket to exist and, on
  Linux only, the PID holder to be the kcserver binary (/proc comm)
- handleShutdownAction drops the registry entry when shutdown fails
  with ENOENT/ECONNREFUSED instead of keeping the dead entry
- add supervisorLiveness unit tests (run under the existing harness)

Fixes posit-dev#16167
@Liang-Psych

Copy link
Copy Markdown
Contributor Author

Heads-up for reviewers: the 4 failing checks (test / unit, test / ext-host, e2e / electron, e2e-tags) all die at workflow template expansion (test-unit.yml:59-60 — POSITRON_GITHUB_RO_USER/PAT container credentials resolve to empty on fork PRs), before any test runs. Unrelated to this diff; internal-branch PRs (e.g. #16171) pass the same jobs.

Could a maintainer please kick off the full suite with secrets so the new supervisorLiveness unit tests actually execute? Happy to address any real failures that surface. Thanks!

@Liang-Psych

Copy link
Copy Markdown
Contributor Author

Follow-up for reviewers/users hitting this on self-hosted Server: I published the ops-side companion as MIT-licensed scripts — kallichore-watchman (session culler + orphan-socket sweeper, audit-first, zero dependencies beyond docker/curl). It encodes the same triple gate from this PR (socket existence + /proc comm + live handshake) as runtime watchdogs for deployments that can't wait for the release train. Happy to transfer or relicense if Posit wants it closer to home.

@jmcphers

Copy link
Copy Markdown
Collaborator

Thanks for this contribution! With this change an abnormal termination gets handled correctly in my testing:

image

I've migrated this PR to #16224 for refinement and testing.

@jmcphers jmcphers closed this Sep 24, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stale supervisor tombstones cannot be pruned or shut down due to Linux TID collision and missing removeByPid in error handler

2 participants