mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-12-06 03:48:31 +00:00
fix: ssh clients do not close when underlying connection writing errors
This commit is contained in:
1 parent
ff179c43a1
commit
ca8d7c41bf
1 file changed
+19
@@ -74,6 +74,13 @@ func (s *Ssh) connect(ctx context.Context, addr string) (client *ssh.Client, err
|
||||
defer done(&err)
|
||||
}
|
||||
|
||||
// Force the SSH transport to shut down when the underlying connection write
|
||||
// fails. handshakeTransport caches this error without closing the transport,
|
||||
// which can leave the shared client permanently unusable while Wait remains
|
||||
// blocked. Closing the connection lets the read and mux loops exit so the
|
||||
// cached client can be discarded and replaced.
|
||||
c = closeOnWriteErrorConn{Conn: c}
|
||||
|
||||
clientConn, chans, reqs, err := ssh.NewClientConn(c, addr, s.config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -95,6 +102,18 @@ func (s *Ssh) connect(ctx context.Context, addr string) (client *ssh.Client, err
|
||||
return client, nil
|
||||
}
|
||||
|
||||
type closeOnWriteErrorConn struct {
|
||||
net.Conn
|
||||
}
|
||||
|
||||
func (c closeOnWriteErrorConn) Write(p []byte) (int, error) {
|
||||
n, err := c.Conn.Write(p)
|
||||
if err != nil {
|
||||
_ = c.Conn.Close()
|
||||
}
|
||||
return n, err
|
||||
}
|
||||
|
||||
// ProxyInfo implements C.ProxyAdapter
|
||||
func (s *Ssh) ProxyInfo() C.ProxyInfo {
|
||||
info := s.Base.ProxyInfo()
|
||||
|
||||
Reference in new issue
Block a user