Skip to content

fix(keyring): reuse one Secret Service session per process - #222

Merged
gnacho merged 1 commit into
mainfrom
fix/221-session-reuse
Sep 18, 2026
Merged

gnacho merged 1 commit into
mainfrom
fix/221-session-reuse

Conversation

@gnacho

@gnacho gnacho commented Sep 18, 2026

Copy link
Copy Markdown
Owner

Closes #221.

Every keyring operation (get/set/delete/search/unlock/adopt) opened a fresh D-Bus connection and negotiated a new DH session. The recurrent gnome-keyring crash investigated in #216 (Ubuntu bug 2161749) is a race in that session negotiation that any client can trigger, so each new session is another chance to hit it.

This keeps one process-wide session, created lazily on first use:

  • All operations in credentials.rs share it, serializing access through a Mutex (engine threads and UI).
  • On a retryable failure (transport error, crypto/session mismatch, daemon restarted) the cached session is dropped and the operation reconnects exactly once. No loops.
  • Domain errors (Locked, NoResult, Prompt, non-UTF-8 secret) never reconnect: a new session cannot change them, and Locked must keep surfacing as-is for the Locked keyring is misreported as AuthRequired (Account Needs Attention) #98/Recover from a locked keyring without restarting the app #214 flows.
  • The cache/reconnect policy is a pure helper with an injectable factory, covered by 6 hermetic tests (reuse, reconnect-once, no loop, domain errors, connect failure, test reset) that need no Secret Service. The existing real-keyring tests are untouched.

The session is leaked by design (the process is long-lived and the crate ties collections/items to &'a self of the service, so a process-wide instance must be 'static anyway); a reconnect leaks one more instance, which is negligible.

735->737 tests passing plus the usual known-flaky real-keyring pair, clippy -D warnings clean, fmt clean. No user-visible strings, no i18n changes.

Every credentials operation opened a fresh D-Bus connection and
negotiated a new DH session. The recurrent gnome-keyring crash
(issue #216, Ubuntu bug 2161749) is a race in that negotiation any
client can trigger, so each new session is one more chance to hit it.

Keep a single process-wide session, created lazily on first use and
shared by get/set/delete/search/unlock/adopt. On a retryable failure
(transport or stale session after a daemon restart) the cached session
is dropped and the operation reconnects exactly once; domain errors
(locked, missing item, dismissed prompt, unreadable secret) never
reconnect. All access is serialized through a Mutex.

The cache/reconnect policy lives in a pure helper with an injectable
factory so it is testable without a Secret Service.

Closes #221
@gnacho
gnacho merged commit 2a7fb44 into main Sep 18, 2026
2 checks passed
@gnacho
gnacho deleted the fix/221-session-reuse branch September 18, 2026 14:37
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.

Reuse a single Secret Service session per process instead of connecting per operation

1 participant