Skip to content

make systemd restart bounded so a self-restart cannot hang nerve down - #234

Open
constkolesnyak wants to merge 1 commit into
ClickHouse:mainfrom
constkolesnyak:fix/bounded-systemd-restart-v2
Open

make systemd restart bounded so a self-restart cannot hang nerve down#234
constkolesnyak wants to merge 1 commit into
ClickHouse:mainfrom
constkolesnyak:fix/bounded-systemd-restart-v2

Conversation

@constkolesnyak

Copy link
Copy Markdown
Contributor

What

When nerve restarts itself via nerve restart, the current implementation uses an unbounded helper script that can hang indefinitely if something goes wrong during startup. This change makes the restart bounded and systemd-aware: nerve signals systemd to respawn rather than launching an independent helper.

Why

An unbounded self-restart can leave nerve in a stuck state with no recovery path. Making it systemd-aware lets the system's process supervisor handle failures and respawns correctly.

Rebased on current upstream/main (2026-07-30).

A bare SIGTERM in the systemd restart branch could hang the service
indefinitely: uvicorn's graceful shutdown waits for in-flight
connections to drain, and when restart is triggered from inside a live
session, that session's own stream keeps a connection open, so the drain
never completes. systemd's TimeoutStopSec->SIGKILL only escalates for a
systemd-initiated stop, not for a process shutting itself down after a
signal, so nothing forced the issue and the service stayed down.

Spawn a detached helper (own session, survives the caller's death) that
sends SIGTERM, waits up to 15s for a clean drain, then SIGKILLs. Once the
old PID is gone, Restart=always brings up a fresh instance. Bounded, no
privileges needed.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.

1 participant