Skip to content

fix(client): a cancel always wins over a late answer; fix flaky tests - #68

Merged
groupsky merged 1 commit into
mainfrom
fix/flaky-agent-tests
Oct 15, 2026
Merged

groupsky merged 1 commit into
mainfrom
fix/flaky-agent-tests

Conversation

@groupsky

Copy link
Copy Markdown
Contributor

What

Flaky tests that failed now and then, also in CI, and one real bug that the stress runs found.

  • TestAgentLogin/approved (test bug): the test SSH server counted a login only after it had answered the client, so the test could read the count too early. The server now counts the end of every handshake, and the tests wait for it.
  • cmd/nodkey TestBrokerStartsAndStops (test bug): a probe script was written and run at once; a child process that a parallel test started at that moment kept a copy of the write handle, so running the probe failed with "text file busy" (go.dev/issue/22315). Test files are now written while holding syscall.ForkLock.
  • cmd/nodkey with two test processes at once (test bug): one could take the other's broker port between restarts. Ports are now reserved across processes.
  • nodkey ssh-agent and nodkey ssh-grant (code bug): Go's HTTP client can still return an answer that arrives during a cancel. After ssh hung up, the agent printed "denied", and with an approval at that same moment it could hand ssh a signature after it had cancelled the request; ssh-grant printed "allowed" after a Ctrl-C. Now a hang-up, the deadline, an agent stop or a signal always wins: no signature, "cancelled", and the signal is raised again. Not a security hole (ssh was already gone; the grants are written in the audit log), but it broke the fail-closed rule.

Tests

CI=true go test -race -count=200 -cpu 1,2,4 -run TestAgent ./internal/client/ and -count=50 ./cmd/nodkey/ pass on Go 1.27 and 1.26. New: TestAgentCancelWinsOverALateAnswer, TestSSHGrantCancelWinsOverALateAnswer.

Review

Two rounds with the security-reviewer agent; no test got weaker, and nodkey run already handled the late answer correctly.

Closes #63

After a hang-up, the deadline, a stop or a signal, ssh-agent gives no signature and ssh-grant says cancelled, even when an answer arrives at the same moment. Three flaky tests now wait for the real events.

Closes #63
@groupsky groupsky added this to the v1 milestone Oct 15, 2026
@groupsky
groupsky merged commit 9ff4a0e into main Oct 15, 2026
7 checks passed
@groupsky
groupsky deleted the fix/flaky-agent-tests branch October 15, 2026 07:25
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.

Flaky tests: ssh-agent TestAgentLogin/approved, and one in cmd/nodkey

1 participant