Skip to content

refactor(keychain): open secret service sessions under the caller's context - #697

Merged
joe0BAB merged 1 commit into
mainfrom
refactor/opensession-ctx
Oct 15, 2026
Merged

joe0BAB merged 1 commit into
mainfrom
refactor/opensession-ctx

Conversation

@joe0BAB

@joe0BAB joe0BAB commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator

OpenSession ran the D-Bus OpenSession call in a goroutine and raced it against time.After in a select. godbus already does this work: CallWithContext finalizes the pending call with ctx.Err() when the context is done and drops a late reply, so the goroutine, both channels and the select were redundant. They also leaked: the channels were unbuffered, so once the timeout branch returned the goroutine blocked forever on its send.

OpenSession now takes a ctx, derives context.WithTimeout from it with the existing session-open timeout (10 s default, so a caller without a deadline still cannot hang on an unresponsive daemon) and issues a single CallWithContext. openSessionRaw and sessionOpenResponse are inlined away and the named results dropped. The timeout error changes from "timed out after 10s" to the wrapped context.DeadlineExceeded.

Every Linux store operation passes its ctx through, consistent with CreateItem, DeleteItem and Unlock. An operation given an already-cancelled context therefore fails immediately instead of succeeding whenever no prompt was needed. The filter_credentials test cleanup relied on the old behavior: it deleted with t.Context(), which is already cancelled inside t.Cleanup. It now uses context.Background() like every other cleanup in the file.

@joe0BAB
joe0BAB marked this pull request as ready for review October 15, 2026 13:33

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🟢 APPROVE

Comment thread store/keychain/internal/go-keychain/secretservice/secretservice.go
Comment thread store/keychain/keychain_test.go
…ontext

OpenSession ran the D-Bus OpenSession call in a goroutine and raced it
against time.After in a select. godbus already does this work:
CallWithContext finalizes the pending call with ctx.Err() when the
context is done and drops a late reply, so the goroutine, both channels
and the select were redundant. They also leaked: the channels were
unbuffered, so once the timeout branch returned the goroutine blocked
forever on its send.

OpenSession now takes a ctx, derives context.WithTimeout from it with the
existing session-open timeout (10 s default, so a caller without a
deadline still cannot hang on an unresponsive daemon) and issues a single
CallWithContext. openSessionRaw and sessionOpenResponse are inlined away
and the named results dropped. The timeout error changes from "timed out
after 10s" to the wrapped context.DeadlineExceeded.

Every Linux store operation passes its ctx through, consistent with
CreateItem, DeleteItem and Unlock. An operation given an already-cancelled
context therefore fails immediately instead of succeeding whenever no
prompt was needed. The filter_credentials test cleanup relied on the old
behavior: it deleted with t.Context(), which is already cancelled inside
t.Cleanup. It now uses context.Background() like every other cleanup in
the file.

Signed-off-by: Johannes Großmann <grossmann.johannes@t-online.de>
@joe0BAB
joe0BAB force-pushed the refactor/opensession-ctx branch from abcce0c to 51a3cc4 Compare October 15, 2026 14:00
@joe0BAB
joe0BAB requested a review from Benehiko October 15, 2026 14:02
@joe0BAB
joe0BAB merged commit 8ab634f into main Oct 15, 2026
27 checks passed
@joe0BAB
joe0BAB deleted the refactor/opensession-ctx branch October 15, 2026 14:16
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.

3 participants