Skip to content

fix: zitadel stop counts an exited server as stopped where nothing collects it - #3626

Open
fforootd wants to merge 4 commits into
mainfrom
claude/cli-stop-unreaped-server
Open

fforootd wants to merge 4 commits into
mainfrom
claude/cli-stop-unreaped-server

Conversation

@fforootd

@fforootd fforootd commented Dec 3, 2026

Copy link
Copy Markdown
Member

Context

  • Found while running the CLI's tests on Vercel CI, whose runner containers have no init as PID 1. There, zitadel stop failed with "Local Zitadel server did not stop" after the server had in fact exited.
  • The same happens in any container started without an init, such as docker run without --init.

Summary

  • Cause: a local server is not the CLI's child. When it exits, PID 1 collects it. Where PID 1 collects nothing, the exited server stays a zombie, and a zombie still answers kill(pid, 0), which is how the launcher checked whether it runs.
  • Fix: on Linux, apps/cli/src/lib/server/local/internal/binary-launcher.ts now also reads the process's state from /proc/<pid>/stat.
    • isPidRunning: a zombie is not running.
    • isRunning: a process group runs only while it has a member that is not a zombie.
  • Unchanged elsewhere: without /proc (macOS, Windows) or where it cannot be read, the signal's answer stands as before.
  • Test: a new unit test in binary-launcher.test.ts (Linux only) leaves a process in its own group as a zombie under a parent that never collects it. It asserts that neither check counts that process as running, while its live parent still counts.

Validation

  • vitest run tests/unit/lib/server/local/internal/binary-launcher.test.ts in apps/cli: 21 passed.
  • The same file against main's binary-launcher.ts: the new test fails, the other 20 pass.
  • pnpm run typecheck in apps/cli: clean. biome check on the changed files: clean.

Release notes / changeset

  • .changeset/cli-stop-unreaped-server.md (@zitadel/cli: patch): zitadel stop stops a local server inside a container started without an init. On Linux the CLI no longer counts a server that has exited as running while nothing has collected it.

Notes

  • apps/cli/skills/zitadel-cli/SKILL.md describes nothing this changes: stop now does what it already says.

Generated by Claude Code

A local server is not the CLI's child, so when it exits PID 1 collects
it. Where PID 1 does not (a container started without an init, such as
`docker run` without `--init`), the server stays a zombie, which still
answers `kill(pid, 0)`, and `zitadel stop` failed with "Local Zitadel
server did not stop". On Linux the launcher now reads a process's state
from /proc: a zombie is not running, and neither is a process group
whose members are all zombies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVJawiDxhgvZh2ypMR
Copilot AI balanced review requested due to automatic review settings December 3, 2026 14:49
@vercel

vercel Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cloud Ready Ready Preview Dec 3, 2026 5:47pm UTC

Request Review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unreadable /proc entries can hide a live child process, causing stopPid to report success without escalating to SIGKILL instead of preserving the signal-based fallback.

1 open issue
What changed in this PR

Fixes local CLI shutdown checks so unreaped Linux zombie processes no longer cause zitadel stop to report failure.

Changes:

  • Checks /proc for live processes and process-group members.
  • Adds a Linux-only zombie-process regression test.
  • Adds a CLI patch changeset.
File Description
apps/​cli/​tests/​unit/​lib/​server/​local/​internal/​binary-launcher.test.ts Tests zombie and live-parent detection.
apps/​cli/​src/​lib/​server/​local/​internal/​binary-launcher.ts Adds process-state inspection to liveness checks.
.changeset/​cli-stop-unreaped-server.md Documents the container shutdown fix.

Review effort: Balanced

groupHasLiveMember counted a /proc/<pid>/stat it could not read as no
member, so where /proc is mounted with hidepid, a live member it may not
read would not count, and stop could report the group gone without
escalating to SIGKILL. procStat now tells a process that is gone (ENOENT,
ESRCH) from one it cannot read, and an unreadable entry leaves the
signal's answer standing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVJawiDxhgvZh2ypMR
The repository's Biome plugin forbids `let`; procStat now parses inside
the try and returns from each branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVJawiDxhgvZh2ypMR
The group scan answered "gone" whenever /proc showed no member of the
group, as under a /proc of another pid namespace or one that hides other
users' processes, although the group still answered the signal. It now
overrules the signal only where it sees members and all of them have
exited, counts a process being collected (X) as exited too, and treats a
stat line it cannot parse as unreadable.

The zombie test is split into one claim per test and waits until the
zombie leads its own group, so a setsid that forks fails it instead of
leaving the scan untested. New tests cover a group whose leader is gone
while a member runs, and a group /proc does not show.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0137eGmVJawiDxhgvZh2ypMR

This branch was successfully deployed

1 active deployment
Preview — b8b7595a Deployed Dec 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants