Repository navigation
fix: close silent ssh connections when keep-alives stop - #32601
Merged
Merged
Conversation
EhabY
force-pushed
the
fix/agentssh-connection-keepalive
branch
from
November 23, 2026 11:12
b43f01c to
98fe08c
Compare
EhabY
force-pushed
the
fix/agentssh-connection-keepalive
branch
2 times, most recently
from
November 23, 2026 11:37
a6f8954 to
3b5dc66
Compare
EhabY
marked this pull request as ready for review
November 23, 2026 12:39
ethanndickson
approved these changes
Nov 24, 2026
ethanndickson
left a comment
Member
There was a problem hiding this comment.
approving for after the coder/ssh PR is merged
Bump the gliderlabs/ssh fork to coder/ssh#8, which runs one keep-alive per connection and closes the whole connection when the client stops answering, instead of only the session channel. - Report connections that end with a read error, such as the tailnet TCP retry limit, or that the keep-alive closes, as network_error. - Document when a vanished client's connection closes.
EhabY
force-pushed
the
fix/agentssh-connection-keepalive
branch
from
November 24, 2026 11:57
512639c to
6a50934
Compare
This branch had an error being deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bumps the
gliderlabs/sshfork to coder/ssh#8 (coder/ssh@467fa35). Before, the agent's keep-alive closed only the session channel on timeout and stopped with the first session, so connections whose session had ended, or that only carried port forwards, were never probed and their connection log rows could stay "Ongoing" indefinitely. The fork now runs one keep-alive per connection and closes the whole connection.CODER_AGENT_SSH_MAX_TIMEOUT(24h by default). The fork now closes afterCountMax+1unanswered intervals like OpenSSH, but over tailnet a vanished client is dropped by the netstack's TCP retry limit about 10 to 30 seconds after the agent's next write, so the probe interval is what matters.SessionKeepAlive.TimedOut()), is reported asnetwork_errorinstead ofclient_closed. The read error is logged asdisconnect_detail(for exampleread tcp ...: operation timed out), like the reconnecting PTY's network errors. A clean close by the client is stillclient_closed. The agent'sConnCallbackwraps the connection to record its first read error; the wrapper forwards the client session ID, and a test covers the failed-handshake log that reads it back.connection-logs.mdnotes that a vanished client's connection stays Ongoing until the agent next sends it data, and the tradeoff of lowering the timeout.Refs CLIENT-1113. Lands ahead of #32444 (client opt-in), as suggested in #32444 (comment).
Verification
TestSSHServer_KeepAliveClosesSilentConnection(MaxTimeout3s, client stops answering while its TCP keeps acknowledging) reportsnetwork_error; it reportsclient_closedwithout theTimedOutmapping.TestSSHServer_ReadErrorReportsNetworkError(the agent's reads start failing) reportsnetwork_errorwith the error asdisconnect_detail; it fails without the wrapper, without the detail, or ifnetworkErrorreturns nil.TestSSHShutdownReasonnow requiresclient_closedfor a client that closes, so it fails ifnetworkErrortreated a clean close as a network error.TestSSHServer_ConnectionFailedLogsClientSessionIDfails if the wrapper drops the client session ID.A throwaway test with a real agent and client over DERP only, where DERP stops relaying without closing (not committed):
mainMaxTimeout2mclient_closednetwork_error[email protected]every 10s, defaultMaxTimeoutclient_closedclient_closedDecision log
CODER_AGENT_SSH_MAX_TIMEOUTby 3, notCountMax+1: the first unanswered probe ends the connection over tailnet, so dividing by 4 would shorten the effective timeout from 24h to 18h.TimedOutis read inside thesync.Oncereport, so both report paths (connection close and process exit) agree. It is set before the connection closes.ConnCallbackrather than read withsshConn.Wait(), which blocks until the read side fails and could delay the report. The wrapper records the error before the fork cancels the connection context, so the report always sees it.io.EOFandnet.ErrClosed(a close by either side) are not network errors.Written with Coder Agents and reviewed by @EhabY.