From 88920c9fbadbf2f2fd3c4379715d9a277e730a50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Wed, 25 Nov 2026 20:13:41 +0800 Subject: [PATCH] Fix hijack-dns not closing finished TCP connections --- route/dns.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/route/dns.go b/route/dns.go index 9502957e..c68809c8 100644 --- a/route/dns.go +++ b/route/dns.go @@ -22,10 +22,11 @@ func (r *Router) hijackDNSStream(ctx context.Context, conn net.Conn, metadata ad return E.Cause(err, "report handshake success") } err = dnsOutbound.NewDNSConnection(ctx, r.dns, conn, metadata) - if err != nil && !E.IsClosedOrCanceled(err) { - return err + if E.IsClosedOrCanceled(err) { + conn.Close() + return nil } - return nil + return err } func (r *Router) hijackDNSPacket(ctx context.Context, conn N.PacketConn, packetBuffers []*N.PacketBuffer, metadata adapter.InboundContext, onClose N.CloseHandlerFunc) error {