From e813a3744f68a7b7fa5e7ae13d50f634fe9f2127 Mon Sep 17 00:00:00 2001 From: patterniha <71074308+patterniha@users.noreply.github.com> Date: Wed, 21 Jan 2026 16:28:30 +0330 Subject: [PATCH] TUN inbound: Cancel ctx when handling is done (#5565) https://github.com/XTLS/Xray-core/pull/5565#issuecomment-3777939907 --------- Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com> --- proxy/tun/handler.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/proxy/tun/handler.go b/proxy/tun/handler.go index 5cf21a75..31fc43c6 100644 --- a/proxy/tun/handler.go +++ b/proxy/tun/handler.go @@ -106,8 +106,9 @@ func (t *Handler) HandleConnection(conn net.Conn, destination net.Destination) { // to close, send completion packets back to the network, and cleanup defer conn.Close() - sid := session.NewID() - ctx := c.ContextWithID(t.ctx, sid) + ctx, cancel := context.WithCancel(t.ctx) + defer cancel() + ctx = c.ContextWithID(ctx, session.NewID()) source := net.DestinationFromAddr(conn.RemoteAddr()) inbound := session.Inbound{