From 8a1ddcebd39b1433fd91a17d6b06cc16718a9552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Wed, 25 Nov 2026 20:08:19 +0800 Subject: [PATCH] Bound SOCKS and HTTP outbound handshakes by timeout --- protocol/http/outbound.go | 13 +++++++------ protocol/socks/outbound.go | 4 +++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/protocol/http/outbound.go b/protocol/http/outbound.go index c25b3d83..61b48cca 100644 --- a/protocol/http/outbound.go +++ b/protocol/http/outbound.go @@ -48,12 +48,13 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL Adapter: outbound.NewAdapterWithDialerOptions(C.TypeHTTP, tag, []string{N.NetworkTCP}, options.DialerOptions), logger: logger, client: sHTTP.NewClient(sHTTP.Options{ - Dialer: detour, - Server: options.ServerOptions.Build(), - Username: options.Username, - Password: options.Password, - Path: options.Path, - Headers: options.Headers.Build(), + Dialer: detour, + Server: options.ServerOptions.Build(), + Username: options.Username, + Password: options.Password, + Path: options.Path, + Headers: options.Headers.Build(), + HandshakeTimeout: C.TCPTimeout, }), }, nil } diff --git a/protocol/socks/outbound.go b/protocol/socks/outbound.go index 344c7988..81868c35 100644 --- a/protocol/socks/outbound.go +++ b/protocol/socks/outbound.go @@ -50,11 +50,13 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL if err != nil { return nil, err } + client := socks.NewClient(outboundDialer, options.ServerOptions.Build(), version, options.Username, options.Password) + client.SetHandshakeTimeout(C.TCPTimeout) outbound := &Outbound{ Adapter: outbound.NewAdapterWithDialerOptions(C.TypeSOCKS, tag, options.Network.Build(), options.DialerOptions), dnsRouter: service.FromContext[adapter.DNSRouter](ctx), logger: logger, - client: socks.NewClient(outboundDialer, options.ServerOptions.Build(), version, options.Username, options.Password), + client: client, resolve: version == socks.Version4, } uotOptions := common.PtrValueOrDefault(options.UDPOverTCP)