Browse Source

TUN inbound: Cancel ctx when handling is done (#5565)

https://github.com/XTLS/Xray-core/pull/5565#issuecomment-3777939907

---------

Co-authored-by: RPRX <[email protected]>
patterniha 4 months ago
parent
commit
e813a3744f
1 changed files with 3 additions and 2 deletions
  1. 3 2
      proxy/tun/handler.go

+ 3 - 2
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{