From 2534bc32023786f0a9b3ce2b6b9496e6174ebcfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus=20Lensb=C3=B8l?= Date: Wed, 18 Mar 2026 17:53:34 -0400 Subject: [PATCH] net/tstun: do not write when Wrapper is closed (#19038) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two methods could deadlock during shutdown when closing the wrapper. Ensure that the writers are aware of the wrapper being closed. Fixes #19037 Signed-off-by: Claus Lensbøl --- net/tstun/wrap.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/net/tstun/wrap.go b/net/tstun/wrap.go index 6fe992575..d0f5b4a0d 100644 --- a/net/tstun/wrap.go +++ b/net/tstun/wrap.go @@ -512,8 +512,9 @@ func (t *Wrapper) injectOutbound(r tunInjectedRead) { if t.outboundClosed { return } - t.vectorOutbound <- tunVectorReadResult{ - injected: r, + select { + case t.vectorOutbound <- tunVectorReadResult{injected: r}: + case <-t.closed: } } @@ -524,7 +525,10 @@ func (t *Wrapper) sendVectorOutbound(r tunVectorReadResult) { if t.outboundClosed { return } - t.vectorOutbound <- r + select { + case t.vectorOutbound <- r: + case <-t.closed: + } } // snat does SNAT on p if the destination address requires a different source address.