Skip to content

fix: close the connection when keep-alive replies stop - #8

Draft
EhabY wants to merge 1 commit into
coder:masterfrom
EhabY:fix/keepalive-timeout-close-connection
Draft

EhabY wants to merge 1 commit into
coder:masterfrom
EhabY:fix/keepalive-timeout-close-connection

Conversation

@EhabY

@EhabY EhabY commented Nov 17, 2026

Copy link
Copy Markdown

When the server keep-alive times out, only the session channel was closed. The connection and its context stayed open, so anything waiting on ctx.Done() (such as the Coder agent's connection reporting) never learned the client was gone. OpenSSH drops the whole connection in this case (ClientAliveCountMax).

This closes the connection instead, which ends every session on it and cancels the context. The previously skipped subtest now covers it by dropping client data through ConnCallback; it fails without the fix.

Part of fixing stale "Ongoing" SSH connection logs; see coder/coder#32353. A fork bump in coder/coder follows.

Verification
$ go test -race -count=20 -run TestSessionKeepAlive .
ok  	github.com/gliderlabs/ssh	24.453s
$ go test -race -count=1 .
ok  	github.com/gliderlabs/ssh	2.846s
# with the original session.go:
$ go test -count=1 -run TestSessionKeepAlive .
    session_test.go:716: connection was not closed after missed keep-alive replies
FAIL

With this fork replaced into coder/coder plus #32353, a client that goes silent (3s agent keep-alive) gets its disconnect reported within 8s; without this change it is never reported.

Written with Coder Agents and reviewed by @EhabY.

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