fix(dialer/ssh): evict dead session when OpenChannel fails (issue #792)

This commit is contained in:
ginuerzh
2026-06-13 19:16:10 +08:00
parent 49ceda6cc2
commit 18c1d6063d
+7
View File
@@ -105,6 +105,13 @@ func (d *sshDialer) Dial(ctx context.Context, addr string, opts ...dialer.DialOp
}
channel, reqs, err := session.OpenChannel(ssh_util.GostSSHTunnelRequest)
if err != nil {
// The cached session is unusable (typically dead but not yet detected
// by IsClosed, e.g. an idle connection silently dropped by NAT). Tear
// it down and evict it so the next Dial rebuilds a fresh session
// instead of retrying against this dead one. Matches the eviction
// pattern in the kcp/quic/icmp dialers.
session.Close()
delete(d.sessions, addr)
return nil, err
}
go ssh.DiscardRequests(reqs)