From cdb2efaabc09923b8edbbd5e08d65a7e7049c9ba Mon Sep 17 00:00:00 2001 From: Fata Nugraha Date: Tue, 3 Sep 2024 12:09:13 +0800 Subject: [PATCH] Fix consistent udp packet loss after the proxy read loop stopped Signed-off-by: Fata Nugraha --- pkg/services/forwarder/udp.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/services/forwarder/udp.go b/pkg/services/forwarder/udp.go index 3226b14c6..5b6b0800b 100644 --- a/pkg/services/forwarder/udp.go +++ b/pkg/services/forwarder/udp.go @@ -38,6 +38,13 @@ func UDP(s *stack.Stack, nat map[tcpip.Address]tcpip.Address, natLock *sync.Mute p, _ := NewUDPProxy(&autoStoppingListener{underlying: gonet.NewUDPConn(s, &wq, ep)}, func() (net.Conn, error) { return net.Dial("udp", fmt.Sprintf("%s:%d", localAddress, r.ID().LocalPort)) }) - go p.Run() + go func() { + p.Run() + + // note that at this point packets that are sent to the current forwarder session + // will be dropped. We will start processing the packets again when we get a new + // forwarder request. + ep.Close() + }() }) }