From cc96187f58c6e56851698cd3bfe4ee45d71f5220 Mon Sep 17 00:00:00 2001 From: Dreamacro <8615343+Dreamacro@users.noreply.github.com> Date: Mon, 5 Apr 2021 23:26:13 +0800 Subject: [PATCH] Fix: trojan grpc udp broken --- adapters/outbound/trojan.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/adapters/outbound/trojan.go b/adapters/outbound/trojan.go index 99f67c306..a87bac7fa 100644 --- a/adapters/outbound/trojan.go +++ b/adapters/outbound/trojan.go @@ -104,15 +104,15 @@ func (t *Trojan) DialUDP(metadata *C.Metadata) (_ C.PacketConn, err error) { return nil, fmt.Errorf("%s connect error: %w", t.addr, err) } tcpKeepAlive(c) + c, err = t.instance.StreamConn(c) + if err != nil { + c.Close() + return nil, fmt.Errorf("%s connect error: %w", t.addr, err) + } } defer safeConnClose(c, err) - c, err = t.instance.StreamConn(c) - if err != nil { - return nil, fmt.Errorf("%s connect error: %w", t.addr, err) - } - err = t.instance.WriteHeader(c, trojan.CommandUDP, serializesSocksAddr(metadata)) if err != nil { return nil, err