Skip to content

Stop the launcher killing the app that is running - #265

Merged
ramonski merged 1 commit into
masterfrom
fix/kill-stale-kills-the-app
Sep 14, 2026
Merged

ramonski merged 1 commit into
masterfrom
fix/kill-stale-kills-the-app

Conversation

@ramonski

Copy link
Copy Markdown
Member

kill_stale() clears a leftover sidecar off the port before spawning a new one. On unix it asked:

lsof -ti :8765

which matches any socket with that port on either end, so it lists the server and everything connected to it. Measured on macOS with one listener and one client:

lsof -ti :PORT               -> 90713 90735
lsof -ti :PORT -sTCP:LISTEN  -> 90713

The busiest client of the sidecar is the webview of a kaisho-desktop that is still running, so an auto-update restart or a second launch would SIGTERM the instance already on screen, along with anything else holding a connection to 127.0.0.1:8765.

The Windows branch, ten lines below, already guards against precisely this. Its comment spells out the failure and even names the case:

that also matched ESTABLISHED and TIME_WAIT entries for client-side connections from the webview […] (including, on a bad day, kaisho-desktop itself since the webview connects back to port 8765)

That fix landed for netstat and never reached lsof. macOS is the platform this ships on first.

-sTCP:LISTEN restricts it to the listener, and the loop also skips its own pid, which is cheap and makes the intent explicit. Builds clean, clippy unchanged.

kill_stale() clears a leftover sidecar off the port before
spawning a new one. On unix it asked:

    lsof -ti :8765

which matches any socket with that port on either end, so
it lists the server and everything connected to it.
Measured on macOS with one listener and one client:

    lsof -ti :PORT                -> 90713 90735
    lsof -ti :PORT -sTCP:LISTEN   -> 90713

The busiest client of the sidecar is the webview of a
kaisho-desktop that is still running, so an auto-update
restart or a second launch would SIGTERM the instance
already on screen, along with anything else holding a
connection to 127.0.0.1:8765.

The Windows branch, ten lines below, already guards
against precisely this. Its comment spells out the failure
and even names the case: including, on a bad day,
kaisho-desktop itself since the webview connects back to
port 8765. That fix landed for netstat and never reached
lsof, and macOS is the platform this ships on first.

-sTCP:LISTEN restricts it to the listener, and the loop
also skips its own pid, which is cheap and makes the
intent explicit.
@ramonski
ramonski merged commit 91559ed into master Sep 14, 2026
@ramonski
ramonski deleted the fix/kill-stale-kills-the-app branch September 14, 2026 14:48
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