Skip to content

fix(connection): start without a keyring, and stop cancelled connects leaking - #527

Merged
EVWorth merged 1 commit into
mainfrom
fix/connection-startup-and-race
Aug 30, 2026
Merged

EVWorth merged 1 commit into
mainfrom
fix/connection-startup-and-race

Conversation

@EVWorth

@EVWorth EVWorth commented Aug 29, 2026

Copy link
Copy Markdown
Owner

Refs #278, #280.

The app would not start without a keyring (#278)

init_keyring called .expect() on every platform, so a locked GNOME Keyring, a Flatpak sandbox with no Secret Service, or a headless session took the app down before it drew a window. Worse, the plaintext-password migration runs from ConnectionStore::new, whose caller also .expect()s — so anyone with a saved profile and a broken keyring could not launch at all.

A missing credential store is a degraded mode, not a fatal one:

  • startup logs a warning and carries on
  • the migration skips a profile it cannot move and leaves the plaintext row in place so a later launch retries, instead of failing construction
  • the status bar says Passwords not saved, so the user learns it now rather than at the next launch

Nothing was needed for the degraded path itself: keyring-core already returns NoDefaultStore as an error rather than panicking, so every password operation fails cleanly once no store is attached.

Cancel during connect leaked a server-side pool (#280)

Disconnect issued before connect resolved found nothing to remove; the resolving connect then added the entry. End state: a live pool on the server that nothing on this side can close, until the app restarts.

  • disconnect records the intent when the id isn't known yet
  • a connect landing on a cancelled id closes it on the server rather than just dropping the reference — the pool is real, so discarding the handle isn't enough
  • disconnect no longer calls the backend for an id this side doesn't have, which used to raise a "not found" error for an ordinary cancel

The existing test asserted the leak as the contract:

// Documenting current behavior: connect wins because disconnect
// ran before the connection was added to activeConnections.
expect(state.activeConnections.map((c) => c.id)).toContain("conn-1");

It now asserts the connection is closed instead.

One note on the fix

I first held the pending-cancel set in a module variable. It leaked between tests and broke an unrelated handles disconnect error case — a fair sign it would leak between windows too, so it lives in store state. That existing test also needed a seeded connection, since the backend is now only asked about connections this side knows about.

1656 frontend tests, 77 unit, 63 integration. clippy/tsc/dprint clean.

🤖 Generated with Claude Code

… leaking

Two ways a connection could go wrong that the app handled badly.

Keyring initialisation called .expect() on every platform, so a locked GNOME
Keyring, a Flatpak sandbox with no Secret Service, or a headless session took
the app down before it drew a window. The plaintext-password migration ran
from ConnectionStore::new, whose caller also .expect()s, so anyone with a
saved profile and a broken keyring could not launch at all.

A missing credential store is a degraded mode, not a fatal one. Startup now
logs a warning and carries on: profiles work, passwords simply are not
remembered between sessions, and the status bar says so rather than leaving
the user to discover it at the next launch. The migration skips a profile it
cannot move and leaves the plaintext row in place so a later launch can retry,
instead of failing construction. Nothing needed to change for the degraded
path itself — keyring-core already answers NoDefaultStore as an error rather
than panicking, so every password operation fails cleanly.

The other is the Cancel-during-connect race. Disconnect issued before connect
resolved found nothing to remove, and the connection was then added by the
resolving connect — leaving a live pool on the server with nothing on this
side able to close it, until the app restarted. Disconnect now records the
intent when the id is not yet known, and a connect that lands on a cancelled
id closes it on the server rather than merely dropping the reference. It also
no longer calls the backend for an id this side does not have, which used to
produce a "not found" error for what is an ordinary cancel.

The existing test asserted the leak as the contract — "Documenting current
behavior: connect wins" — so it now asserts the connection is closed instead.
Moving the pending-cancel set into store state rather than a module variable
was not cosmetic: as a module variable it leaked between tests and broke an
unrelated disconnect-error case, which is a fair sign it would have leaked
between windows too.

Refs #278, #280
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