From 261b8a1d0677f3e3f66da7d36540763cdb5815a4 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Tue, 10 Jan 2023 13:21:32 +0800 Subject: [PATCH] fix: vmess udp --- adapter/outbound/vmess.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/adapter/outbound/vmess.go b/adapter/outbound/vmess.go index 8d018caa..08fd9f37 100644 --- a/adapter/outbound/vmess.go +++ b/adapter/outbound/vmess.go @@ -290,16 +290,6 @@ func (v *Vmess) ListenPacketContext(ctx context.Context, metadata *C.Metadata, o } return v.ListenPacketOnStreamConn(c, metadata) } - c, err = dialer.DialContext(ctx, "tcp", v.addr, v.Base.DialOptions(opts...)...) - if err != nil { - return nil, fmt.Errorf("%s connect error: %s", v.addr, err.Error()) - } - tcpKeepAlive(c) - defer func(c net.Conn) { - safeConnClose(c, err) - }(c) - - c, err = v.StreamConn(c, metadata) return v.ListenPacketWithDialer(ctx, dialer.NewDialer(v.Base.DialOptions(opts...)...), metadata) } @@ -315,10 +305,18 @@ func (v *Vmess) ListenPacketWithDialer(ctx context.Context, dialer C.Dialer, met } c, err := dialer.DialContext(ctx, "tcp", v.addr) + if err != nil { + return nil, fmt.Errorf("%s connect error: %s", v.addr, err.Error()) + } + tcpKeepAlive(c) + defer func(c net.Conn) { + safeConnClose(c, err) + }(c) + + c, err = v.StreamConn(c, metadata) if err != nil { return nil, fmt.Errorf("new vmess client error: %v", err) } - return v.ListenPacketOnStreamConn(c, metadata) }