You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A stopping daemon closes new connections, so commands get DAEMON_CONNECTION_LOST, not the documented DAEMON_STOPPING #1301
src/daemon/server.ts:740-743 (#accept) closes every new connection once #stopping is set. So during the stop window:
A command from a new connection fails with DAEMON_CONNECTION_LOST ("Daemon connection closed"). The docs say it fails with DAEMON_STOPPING: website/src/content/docs/docs/worker/running-the-daemon.mdx:119 and :129, website/src/content/docs/docs/worker/configuration.mdx:49.
A second simlock daemon stop fails the same way. The comment at src/daemon/server.ts:847-851 says daemon.stop "stays reachable ... while the daemon is already #stopping", but that holds only for connections opened before the stop.
Evidence: the #1295 reproduction (e2e/daemon-lifecycle.test.ts, branch bug/1295-repro). Its teardown's daemon stop, sent while the old daemon still shuts down an idle device, failed:
Error: daemon stop failed before teardown of .../daemon.sock: {"error":{"code":"DAEMON_CONNECTION_LOST","message":"Daemon connection closed"}}
Confirmed. src/daemon/server.test.ts › "answers a connection opened while the daemon is stopping: status.get with DAEMON_STOPPING, daemon.stop with stopping true", on bug/1301-repro (24a62e7). It holds settle open after stop(), opens a new admin connection, and sends hello, status.get, daemon.stop.
pnpm exec vitest run --project unit src/daemon/server.test.ts -t "opened while the daemon is stopping"
- { "ok": true },
- { "error": { "code": "DAEMON_STOPPING" }, "ok": false },
- { "ok": true, "payload": { "stopping": true } },
+ "connection closed",
+ "connection closed",
+ "connection closed",
❯ src/daemon/server.test.ts:2796:23
Root cause
Defect. src/daemon/server.ts:740 (#accept) closes every new socket once #stopping is set, so no frame on it reaches #dispatchLine. The DAEMON_STOPPING gate (:880) and the daemon.stop exception (:852) only ever see connections opened before the stop. The endpoint keeps listening until host.stop() at :666, so clients connect and then lose the connection. No ADR asks for this; the docs and the comment at :847-851 describe the dispatch gates.
Simplest fix
Gate #accept on a flag set when #stop reaches #closeConnections() (:660), not on #stopping. Connections opened during the drain then get DAEMON_STOPPING or the daemon.stop reply. Ones that arrive after the close are still closed at once, so none is left open after host.stop(). With the gate removed, the whole file passes (138 tests).
Alternatives rejected
Drop the #accept gate entirely: a socket accepted between #closeConnections() and host.stop() is never closed.
Change the docs to DAEMON_CONNECTION_LOST: a second daemon stop or a daemon start retry cannot tell a stopping daemon from a crashed one.
Map DAEMON_CONNECTION_LOST to DAEMON_STOPPING in the client: the client cannot know why the socket closed.
Risk
#releaseFailedStart (:689) also closes connections: set the same flag there.
The uplink goes through #accept too (acceptUplink): a gateway that reconnects during the drain now gets a session that refuses everything with DAEMON_STOPPING, and the close ends it.
src/cli/environment.ts:26-30 already treats both codes as a failed start; check that daemon start against a stopping daemon prints the documented DAEMON_STOPPING.
Activity
V3RON commentedon Nov 5, 2026
Reproduction
Confirmed.
src/daemon/server.test.ts› "answers a connection opened while the daemon is stopping: status.get with DAEMON_STOPPING, daemon.stop with stopping true", onbug/1301-repro(24a62e7). It holdssettleopen afterstop(), opens a new admin connection, and sendshello,status.get,daemon.stop.Root cause
Defect.
src/daemon/server.ts:740(#accept) closes every new socket once#stoppingis set, so no frame on it reaches#dispatchLine. TheDAEMON_STOPPINGgate (:880) and thedaemon.stopexception (:852) only ever see connections opened before the stop. The endpoint keeps listening untilhost.stop()at:666, so clients connect and then lose the connection. No ADR asks for this; the docs and the comment at:847-851describe the dispatch gates.Simplest fix
Gate
#accepton a flag set when#stopreaches#closeConnections()(:660), not on#stopping. Connections opened during the drain then getDAEMON_STOPPINGor thedaemon.stopreply. Ones that arrive after the close are still closed at once, so none is left open afterhost.stop(). With the gate removed, the whole file passes (138 tests).Alternatives rejected
#acceptgate entirely: a socket accepted between#closeConnections()andhost.stop()is never closed.DAEMON_CONNECTION_LOST: a seconddaemon stopor adaemon startretry cannot tell a stopping daemon from a crashed one.DAEMON_CONNECTION_LOSTtoDAEMON_STOPPINGin the client: the client cannot know why the socket closed.Risk
#releaseFailedStart(:689) also closes connections: set the same flag there.#accepttoo (acceptUplink): a gateway that reconnects during the drain now gets a session that refuses everything withDAEMON_STOPPING, and the close ends it.src/cli/environment.ts:26-30already treats both codes as a failed start; check thatdaemon startagainst a stopping daemon prints the documentedDAEMON_STOPPING.Written by an agent.
test(daemon): a connection opened after the connections were closed i…
fix(daemon): a stopping daemon answers new connections with DAEMON_ST…