From d9a44960d7efacc0143b391df5aaf44d44e57d43 Mon Sep 17 00:00:00 2001 From: hklcf Date: Sat, 23 May 2026 09:53:20 +0800 Subject: [PATCH] fix(route): prevent use-after-close race on PacketConn in sniffing loop When ctx is cancelled during packet sniffing, inputPacketConn.Close() is called while a goroutine may still be calling ReadPacket() and SetReadDeadline() on the same conn. Wait for the goroutine to finish after close to prevent concurrent access. Fixes #4161 --- route/route.go | 1 + 1 file changed, 1 insertion(+) diff --git a/route/route.go b/route/route.go index d7894c6f1a..9828efd32c 100644 --- a/route/route.go +++ b/route/route.go @@ -726,6 +726,7 @@ func (r *Router) actionSniff( case <-done: case <-ctx.Done(): inputPacketConn.Close() + <-done fatalErr = ctx.Err() return }