machine reconnect: managed control socket refuses the session, probe falls back to BatchMode=yes and spends an MFA passcode (follow-up to #4490)
Summary
PR #4490 reuses the authenticated managed SSH transport across setup, saved machines and API requests, fixing the case #4276 described: an endpoint-capability probe opening a separate BatchMode=yes bridge that cannot answer an MFA prompt.
There is an unhandled branch. When the managed control socket exists but refuses the session, reuse fails, OpenSSH disables multiplexing, and the probe falls back to exactly the BatchMode=yes bridge #4276 identified as the original defect. MFA has already succeeded by that point, so the passcode is spent and the authenticated connection is discarded.
Both halves of #4490's fix live in src/remote/attach.rs and both assume the managed ControlPath is either free or reusable:
ssh_authentication_command()buildsssh -o BatchMode=no -o NumberOfPasswordPrompts=3 -T <target> exit.BatchMode=nois deliberate and correct, and MFA does succeed. But the command's only product is the master it leaves behind on the managedControlPath— it runsexitand nothing else. When that path is already held by a master that refuses sessions, OpenSSH printsalready exists, disabling multiplexing, theexitruns over a throwaway direct connection, and no master is installed. Nothing checks for this, soreconnectreports the authentication it performed rather than the master it failed to leave.RemoteSsh::new_noninteractive()now derivesmanagefrommultiplexing && config.remote.manage_ssh_configand goes through the same managed config. It therefore meets the same occupied socket, is refused, and falls back — this time withBatchMode=yes, which is the fallback #4276 was written to eliminate.
So the two paths fail in sequence and the second one reports the error, which is why the visible symptom (remote platform detection failed) names the probe rather than the recovery step that actually went wrong.
Versions
client: 0.9.3
local server: 0.9.3
remote server: 0.9.3
client OS: macOS 15 (arm64)
server OS: Linux x86_64
sshd: AuthenticationMethods publickey,keyboard-interactive(Quote herdr status, not herdr --version — they disagree while a server predates its binary, which herdr status reports as server_binary_stale.)
Reproduction
With a saved machine whose managed control socket is already present:
$ herdr machine reconnect devvm
mux_client_request_session: session request failed: Session open refused by peer
(user@host) Duo two-factor login for user
Enter a passcode:
Passcode: ********
Success. Logging you in...
ControlSocket /tmp/hssh-501/<hash> already exists, disabling multiplexing
Error: remote platform detection failed: mux_client_request_session: session
request failed: Session open refused by peer ... Permission denied (keyboard-interactive).Line 1: reuse attempted, refused. Line 5: MFA succeeded. Line 6: OpenSSH cannot install the new connection as master. Line 7: the probe (remote platform detection) falls back to the BatchMode bridge, which by construction cannot answer the second factor.
herdr machine status fails the same way permanently, because it opens the same extra session.
It is not sshd's MaxSessions
Counted rather than assumed. Twelve sessions opened one at a time against the blocking master:
Master running (pid=45686)
[1] refused by peer
[2..12] refused by peerRefused 12 for 12 starting with the first. MaxSessions defaults to 10, so a server-side cap would have let roughly nine through. A master created by hand with ssh -M -N -f against the same host accepts concurrent sessions normally.
Workaround
Close the blocking master first; reconnect then succeeds in about nine seconds.
shopt -s nullglob
for s in "/tmp/hssh-$(id -u)"/*; do ssh -S "$s" -O exit "$HOST" 2>/dev/null; done
rm -f "/tmp/hssh-$(id -u)"/*
herdr machine reconnect "$LABEL"Suggested direction
Three options, roughly in order of how cheap they look from outside:
- Verify the product, not the act. After
ssh_authentication_command()returns success, check that the managedControlPathnow answers (ssh -O check). If it does not, the authentication bought nothing and the user should be told that, not handed a later probe failure. - Treat
Session open refused by peeron the managed socket as recoverable. Retire the refusing master (-O exit, then unlink) and let the freshly authenticated connection take the path. This is exactly what the workaround above does by hand, and it succeeds in about nine seconds every time. - Refuse the
BatchMode=yesfallback once interactive auth has already run. That fallback cannot answer a second factor by construction, so in an MFA environment reaching it is always a failure. Failing loudly beats spending a passcode silently.
Option 1 alone would have turned a day of misdiagnosis into one clear error message, even without fixing the underlying refusal.
Questions
- Does this reproduce without mandatory two-factor auth? If the BatchMode fallback can authenticate unaided, the refusal is invisible and only affects MFA users.
- Is
machine statuseverreachablefor a saved machine, given it opens the extra session that gets refused? - Since 0.9.2 open clients recheck failed machines every 30 s. Are those rechecks what occupies the master? #4721 reports a 30 s reconnect delay after a lid open, which may be the same loop.
Related
- #4490 (merged 2026-09-22) — the transport-reuse fix this follows up
- #4276 (closed, superseded) — Root Cause describes this exact
BatchMode-probe failure at
machine add - #3763 (closed) — the MFA
machine addbug behind both - #4582 — saved machine stuck in Attention after the SSH agent refuses to sign during reconnect; same stuck-state shape
- #4721 — saved machine takes 30 s+ to reconnect after a lid open
- #4350 —
machine addfails when the user's ssh config declaresRemoteForward/ExitOnForwardFailure; same root shape of herdr's ssh invocation colliding with user ssh config - #4496 — Tailscale login URL hidden, stuck Reconnecting
Caveat
The exact OpenSSH interaction is inferred from its stderr (already exists, disabling multiplexing) plus the observed outcome, not from instrumenting herdr. If the master should in fact have been replaced there, that reconstruction is the part to doubt first. The code claims come from reading the merged #4490 diff.
Source: herdrdev/herdr