Skip to content

fix(cli): bound the keyring availability probe - #5348

Open
shunxinyi-ljs wants to merge 2 commits into
Tencent:mainfrom
shunxinyi-ljs:fix/cli-keyring-probe-timeout
Open

shunxinyi-ljs wants to merge 2 commits into
Tencent:mainfrom
shunxinyi-ljs:fix/cli-keyring-probe-timeout

Conversation

@shunxinyi-ljs

Copy link
Copy Markdown
Contributor

Description

NewBestEffortStore probes the OS keyring with a no-op Get before the CLI can read credentials, and that probe has no bound. On a host where the secret service exists but does not answer (locked GNOME keyring waiting for its unlock prompt; a DBus socket that accepts and stalls), the call did not return: weknora config view and weknora doctor --offline produced no output and were still running when killed after 10 s. Both commands are supposed to answer from local state only.

The file store already works on those hosts, so waiting longer buys nothing. The probe now runs in a goroutine with a 2 s budget and falls back to NewFileStore() on timeout. Its result is still the only thing that decides between keyring and file store.

Behavior change worth knowing: on an unusable-keyring host, commands that previously hung now continue with the file store.

Type of Change

  • 🐛 Bug fix
  • 🧪 Test

Related Issue

None.

Testing

Baseline 26723dca, WSL Ubuntu 24.04 where /run/user/0/bus exists but never answers:

  • timeout -s KILL 10 ./weknora config view → no output, rc=137.
  • timeout -s KILL 10 ./weknora doctor --offline → no output, rc=137.
  • DBUS_SESSION_BUS_ADDRESS=unix:path=/tmp/nonexistent-bus.sock ./weknora config view → returns in 1.3 s, which pins the probe (not the command) as the blocker.

With the patch on the same host:

  • config view → rc=0 in 3.9 s, reporting "secrets":"file …".
  • go test ./internal/secrets/... -count=1 — pass.
  • go test ./cmd/config ./cmd/doctor -count=1 — pass; these two used to time out on this host.
  • TestNewBestEffortStoreFallsBackWhenTheProbeHangs substitutes a probe that blocks forever and asserts the file store is returned. On the baseline it cannot run because the probe seam is what the patch adds.

Checklist

  • git diff --check origin/main...HEAD passes
  • Changed source files are formatted
  • Targeted tests for the changed packages pass
  • Full-repository checks were run, or any unrelated/environment-dependent failures are documented above
    (full go build ./... needs a cgo vector-store build this machine cannot complete; package-scoped checks were used instead)
  • Self-reviewed the code
  • Added/updated tests covering the change
  • Updated related documentation (not applicable)
  • Breaking changes are clearly called out in the description above (behavior change on unusable keyrings)

NewBestEffortStore probes the OS keyring before every command. On a host where
the secret service exists but never answers (locked GNOME keyring waiting for
the unlock prompt, a DBus socket that accepts and stalls) that Get blocks
forever, so commands such as 'weknora config view' or 'weknora doctor --offline'
produce no output at all. Give the probe a two-second budget and fall back to
the file store, which is a working credential store on those hosts.
@shunxinyi-ljs
shunxinyi-ljs marked this pull request as ready for review November 10, 2026 05:18
The probe goroutine reads keyringGet when it starts. When the probe times out, NewBestEffortStore returns before the goroutine has read the seam, so the test cleanup that restores keyringGet raced with that read (reported by -race on all three platforms).

Close the goroutine lifecycle instead: the fake seam signals when it returns and the cleanup waits for that signal before restoring the seam. The fake also drops its unused parameter names so revive stops flagging them.

This branch has not been deployed

No deployments
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