From f07b22d4dffb345c90fed07160c3ba9cb5fc5fff Mon Sep 17 00:00:00 2001 From: Nick O'Neill Date: Thu, 24 Sep 2026 15:39:41 -0700 Subject: [PATCH] Reapply "wgengine/netstack: avoid returning from sender goroutines on error (#21332) (#21445)" This reverts commit d93ea830ed5b0a699da353b989ccae8c694d9a84. --- wgengine/netstack/netstack.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/wgengine/netstack/netstack.go b/wgengine/netstack/netstack.go index 17ba3dfa6..f4092a5d7 100644 --- a/wgengine/netstack/netstack.go +++ b/wgengine/netstack/netstack.go @@ -1073,7 +1073,16 @@ func (ns *Impl) inject() { if sendToHost { if err := ns.tundev.InjectInboundPacketBuffer(pkt, inboundBuffs, inboundBuffsSizes); err != nil { ns.logf("netstack inject inbound: %v", err) - return + // When failing to inject an outbound packet buffer, log the error, but + // continue serving the ReadContext for sending subsequent packets, as + // nothing manages or restarts a failed inject. An error here + // only applies to the current packet and should not terminate the long-lived + // packet pump. + // The exception to this is if the context has ended, indicating a shutdown. + if ns.ctx.Err() != nil { + return + } + continue } } else { // Self-addressed packet: deliver back into gVisor directly @@ -1088,7 +1097,16 @@ func (ns *Impl) inject() { if err := ns.tundev.InjectOutboundPacketBuffer(pkt); err != nil { ns.logf("netstack inject outbound: %v", err) - return + // When failing to inject an outbound packet buffer, log the error, but + // continue serving the ReadContext for sending subsequent packets, as + // nothing manages or restarts a failed inject. An error here + // only applies to the current packet and should not terminate the long-lived + // packet pump. + // The exception to this is if the context has ended, indicating a shutdown. + if ns.ctx.Err() != nil { + return + } + continue } } }