Repository navigation
Retry SSH sessions a host refuses instead of logging in on their own - #605
Open
thiblahute wants to merge 1 commit into
Open
thiblahute wants to merge 1 commit into
thiblahute wants to merge 1 commit into
Conversation
sshd's default MaxSessions 10 counts a session until its remote command ends, a moment after the client exits (longer when a command killed here on a timeout still runs there), so a burst of reads, such as a site's pages in the Files preview, could be refused below Roamgate's eight slots: OpenSSH then logged in on its own for each and printed "mux_client_request_session: session request failed: Session open refused by peer", which became the first line of the error shown. The process helpers now run multiplexed commands with ProxyCommand=false ahead of the user's config, so a refused session fails instead: the command has not run, and runs again over the master after 0.2, 0.5, 1 and 2 seconds, keeping its slot, then on a connection of its own. For five seconds after a refusal the destination gives no new slot past the ones in use, less one. A gone socket runs the command cold at once. OpenSSH's lines about the master are left out of the stderr returned. A command run with a deadline also ends on the host two seconds after it: the remote line runs it under /bin/sh with a watchdog that kills the session's process group, so a command waiting on nothing it reads no longer holds one of the host's sessions for good. Until then its session is still counted against the destination's slots. When the host refuses eight sessions in a row over at least fifteen seconds, none served in between (an sshd that stopped reaping its session processes keeps them all counted), the master is closed and opened again at once, at most once a minute, and commands go straight to a connection of their own until it is back.
This branch has not been 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 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.
Summary
Retry an SSH command whose session the host refuses over the shared master, instead of letting OpenSSH log in on its own, and stop commands killed at their deadline from holding a host session for good.
Why
sshd's default
MaxSessions 10counts a session until its remote command ends, a moment after the client exits, and longer when a command killed here on a timeout still runs there. A burst of reads (a site's pages in the Files preview, for example) could therefore be refused below Roamgate's eight slots. OpenSSH then fell back to a login of its own for each command and printedmux_client_request_session: session request failed: Session open refused by peer, which became the first line of the error shown.A command waiting on nothing it reads (a locked macOS keychain under
glab auth status, a stalled network call) never notices its client is gone, so each one killed at its deadline kept one of the host's sessions until the master closed.A host can also keep a connection's sessions taken for good: macOS's sshd has been seen to stop reaping its session processes, which stay zombies, so every session of that master stays counted and every command is refused.
What changed
server/src/bridge/ssh-command.ts: the process helpers run multiplexed commands with-o ProxyCommand=falseahead of the user's config (SSH_MUX_ONLY_ARGS), so a session the master cannot open fails instead of logging in on its own. Not on Windows clients (no POSIXfalse).server/src/bridge/ssh-sessions.ts(runSshCommand):withoutMuxNoise).withRemoteDeadline:/bin/shwith a watchdog that kills the session's process group 2 s past the deadline and goes away when the command ends. PowerShell commands (Windows hosts) are left as they are. A client killed here frees its slot at once, but the host's session is counted against the destination until that remote deadline.server/src/bridge/ssh-master.ts:recycle()closes the ready master and opens a new one at once.server/src/bridge/ssh-metrics.ts:copySshAnnotationkeeps a retry argv's debug annotation.docs/ARCHITECTURE.md: SSH transport section.Callers that spawn the argv themselves (
holdSshSession: uploads, search) keep OpenSSH's own fallback.Verification
bun test server/src/bridge/ssh-sessions.test.ts server/src/bridge/ssh-refused.test.ts server/src/bridge/ssh-openssh.test.ts server/src/bridge/ssh-master.test.ts server/src/bridge/ssh-command.test.ts server/src/bridge/ssh-metrics.test.ts: 63 pass. New tests, which fail onmain:ssh-refused.test.ts"commands a host refuses past its sessions wait and run over the master" (a fakesshrefusing past a session count)ssh-openssh.test.ts"runs over the master without OpenSSH's own fallback login", "runs a command whose master socket is gone on its own connection"ssh-sessions.test.ts"retries a refused session over the master after a short wait", "runs a session refused every time on its own connection at last", "gives no new slot for a while after a refusal", "recycles a master only while its host serves no session at all", "withoutMuxNoise keeps the command's own lines", and the "remote deadlines" groupssh-master.test.ts"recycles a master whose host keeps refusing its sessions"bun run format:check,bun run lint(only the existingTerminalView.tsxwarning),bun run typecheck:bun,bun run test:quickwith an isolatedHOME/TMPDIR.Compatibility
Server only. Commands with a deadline now run on the host as
exec /bin/sh -c '<watchdog>' roamgate-deadline <seconds> '<command>'; the commands Roamgate sends are POSIX sh, and the outer line parses alike in sh, bash, zsh and fish. A userProxyCommandorProxyJumpstill applies to the master and to cold runs; only the multiplexed attempt ignores it.