From 2b45ea59bd30a9170f74500693272e4f0a97bbbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Sat, 14 Nov 2026 06:14:48 +0000 Subject: [PATCH] Fix missing handshake timeout in SSH outbound --- protocol/ssh/outbound.go | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/protocol/ssh/outbound.go b/protocol/ssh/outbound.go index a9ff8116..f91615c3 100644 --- a/protocol/ssh/outbound.go +++ b/protocol/ssh/outbound.go @@ -145,20 +145,19 @@ func (s *Outbound) connect(ctx context.Context) (client *ssh.Client, err error) if err != nil { return nil, err } - if ctx.Done() != nil { - handshakeConn := conn - stopContext := context.AfterFunc(ctx, func() { - _ = handshakeConn.Close() - }) - defer func() { - if !stopContext() { - s.client = nil - s.clientConn = nil - client = nil - err = ctx.Err() - } - }() - } + ctx, cancel := context.WithTimeout(ctx, C.TCPTimeout) + defer cancel() + stopContext := context.AfterFunc(ctx, func() { + _ = conn.Close() + }) + defer func() { + if !stopContext() { + s.client = nil + s.clientConn = nil + client = nil + err = E.Cause(ctx.Err(), "connect to ssh server") + } + }() config := &ssh.ClientConfig{ User: s.user, Auth: s.authMethod,