Skip to content

Let the gateway be asked to exit, and record the token break - #121

Merged
fylorn merged 1 commit into
mainfrom
feat/windows-shutdown
Sep 23, 2026
Merged

fylorn merged 1 commit into
mainfrom
feat/windows-shutdown

Conversation

@fylorn

@fylorn fylorn commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Windows has no SIGTERM, and the desktop app has two things it must do: restart core after a configuration change, and stop core before installing an update and wait for it to be gone — without that wait the new instance collides with the lock the old one has not released yet (there is a comment in supervisor.rs on the lite side recording that this was measured, not guessed).

On that platform the only thing left is a hard kill, which means SQLite's WAL gets no chance to settle and in-flight requests are cut mid-response.

So it is a request rather than a signal — and it is slightly better than one: it is acknowledged. The desktop app knows it was received instead of firing and guessing. Both platforms use it, because a path that only runs on one platform is a path nobody exercises.

Two details that are easy to get wrong

The handler answers before the switch is thrown. Throwing it immediately risks the process being gone before the response is written, and what the client sees then is a reset connection — indistinguishable from core crashing, on the one exit it asked for itself.

The switch stores a request that arrives before anyone is waiting (notify_one, not notify_waiters). During the first milliseconds of startup the control plane can be answering while the main loop has not reached its select yet, and dropping that request leaves a process that never exits. There is a test for exactly that ordering.

The protocol version, which #114 should have bumped

It goes to 12. A request without Authorization: Bearer now gets 401 for everything, /status included. A client written against 11 never sees the bump — it hits the 401 first — but that line is this protocol's change history, and "when did a credential become required" is something a reader has to be able to find.

Verified end to end

The smoke script now asks core to exit and waits for the process to be gone (not the socket — a wedged process can lose its socket and still be there). 55 passed, 0 failed.

That is the only end-to-end check of the chain: an HTTP request throws the switch, the main loop's select wakes, the process leaves. Unit tests can show the switch flips; they cannot show it is wired to the main loop — and the shape of getting that wrong is a 202 and a gateway that keeps running happily.

🤖 Generated with Claude Code

@fylorn
fylorn force-pushed the feat/windows-shutdown branch 2 times, most recently from 13ac1aa to d2d9976 Compare September 23, 2026 06:18
… break

Windows has no SIGTERM, and the desktop app has two things it must do:
restart core after a configuration change, and stop core before installing
an update and *wait for it to be gone* -- without that wait the new one
collides with the lock the old one has not released yet. On that platform
the only thing left is a hard kill, which means SQLite's WAL gets no
chance to settle and in-flight requests are cut mid-response.

So it is a request rather than a signal, and it is slightly better than
one: it is acknowledged. The desktop app knows it was received instead of
firing and guessing.

Both platforms use it. A path that only runs on one platform is a path
nobody exercises.

The handler answers before the switch is thrown. Throwing it immediately
risks the process being gone before the response is written, and what the
client sees then is a reset connection -- indistinguishable from core
crashing, on the one exit it asked for itself.

The switch stores a request that arrives before anyone is waiting
(`notify_one`, not `notify_waiters`). During the first milliseconds of
startup the control plane can be answering before the main loop reaches
its select, and dropping that request leaves a process that never exits.

The protocol version goes to 12, which #114 should have done: a request
without `Authorization: Bearer` now gets 401 for everything, `/status`
included. A client written against 11 never sees the bump -- it hits the
401 first -- but that line is this protocol's change history, and "when
did a credential become required" is something a reader has to be able to
find.

The smoke script now asks core to exit and waits for the process to be
gone. That is the only end-to-end check of the chain: an HTTP request
throws the switch, the main loop's select wakes, the process leaves. Unit
tests can show the switch flips; they cannot show it is wired to the main
loop -- and the shape of getting that wrong is a 202 and a gateway that
keeps running.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@fylorn
fylorn force-pushed the feat/windows-shutdown branch from d2d9976 to 0f35362 Compare September 23, 2026 06:25
@fylorn
fylorn merged commit ff6511a into main Sep 23, 2026
1 check passed
@fylorn
fylorn deleted the feat/windows-shutdown branch September 23, 2026 06:33
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