Repository navigation
fix: close the connection when keep-alives stop and allow per-connection settings - #8
Merged
EhabY merged 6 commits intoNov 24, 2026
Conversation
EhabY
marked this pull request as ready for review
November 20, 2026 09:59
EhabY
added a commit
to coder/coder
that referenced
this pull request
Nov 20, 2026
…orten the keep-alive 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. - Divide CODER_AGENT_SSH_MAX_TIMEOUT by CountMax+1 to keep the 72h default with the fork's OpenSSH count. - Report connections closed by the keep-alive as network_error. - Let clients shorten the keep-alive for their connection with CODER_SSH_CLIENT_ALIVE_INTERVAL and CODER_SSH_CLIENT_ALIVE_COUNT_MAX.
EhabY
added a commit
to coder/coder
that referenced
this pull request
Nov 20, 2026
…live 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. - Divide CODER_AGENT_SSH_MAX_TIMEOUT by CountMax+1 to keep the 72h default with the fork's OpenSSH count. - Report connections closed by the keep-alive as network_error. - Let clients shorten the keep-alive for their connection with CODER_SSH_CLIENT_ALIVE_INTERVAL and CODER_SSH_CLIENT_ALIVE_COUNT_MAX.
ethanndickson
approved these changes
Nov 23, 2026
EhabY
added a commit
to coder/coder
that referenced
this pull request
Nov 23, 2026
…live 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. - Divide CODER_AGENT_SSH_MAX_TIMEOUT by CountMax+1 to keep the 72h default with the fork's OpenSSH count. - Report connections closed by the keep-alive as network_error. - Let clients shorten the keep-alive for their connection with CODER_SSH_CLIENT_ALIVE_INTERVAL and CODER_SSH_CLIENT_ALIVE_COUNT_MAX.
EhabY
added a commit
to coder/coder
that referenced
this pull request
Nov 23, 2026
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 closed by the keep-alive as network_error. - Document when a vanished client's connection closes.
EhabY
added a commit
to coder/coder
that referenced
this pull request
Nov 23, 2026
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
added a commit
to coder/coder
that referenced
this pull request
Nov 23, 2026
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
added a commit
to coder/coder
that referenced
this pull request
Nov 24, 2026
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
added a commit
to coder/coder
that referenced
this pull request
Nov 24, 2026
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. Connections whose session had ended, or that only carried port forwards, were never probed and could stay Ongoing in the connection log indefinitely. - Keep probing every third of CODER_AGENT_SSH_MAX_TIMEOUT (24h by default) - Report connections that end with a read error, such as the tailnet TCP retry limit after a client vanishes, or that the keep-alive closes, as network_error with the read error as disconnect_detail - Keep reporting a clean client close as client_closed - Wrap the agent's connection to record its first read error while still forwarding the client session ID - Document when a vanished client's connection closes and the tradeoff of lowering the timeout Closes CLIENT-1113
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The server keep-alive had two gaps that let a silent client keep its connection open forever:
ctx.Done(), such as the Coder agent's connection reporting, never learned the client was gone.The keep-alive now runs once per connection from
HandleConn, sends a global[email protected]request, and, like OpenSSH, closes the connection afterClientAliveCountMaxunanswered probes,(ClientAliveCountMax+1) × ClientAliveIntervalafter the last reply. The previous check fired one interval earlier, soClientAliveCountMax: 1closed healthy clients before probing them. Clients reply to the global request with success or failure; either counts as alive. The previously skipped subtest covers it: the session ends, then the client drops all data, and the connection must close.Servers can override the keep-alive for one connection with
SessionKeepAlive.SetClientAlive(interval, countMax), like an sshd_configMatchblock; a value of zero or less disables it.SessionKeepAlive.TimedOut()reports whether the keep-alive closed the connection, so a server can tell a dead client from a clean close. The loop therefore starts for every connection and waits on a stopped ticker until a keep-alive is set; partial settings disable it instead of closing at the first tick. It readsctx.Done()and the keep-alive once, before it starts, becauseSetValue(for example on agent forwarding) rewrites the context without a lock. Part of fixing stale "Ongoing" SSH connection logs; see coder/coder#32353. coder/coder#32521 bumps the fork and coder/coder#32444 usesSetClientAlive.Verification
coder/coder
./agent/...(with-raceforagentssh) and thecliSSH tests pass with this fork replaced in.Written with Coder Agents and reviewed by @EhabY.