From 86b1ccaec338d26c200cfa3420373937270f99a1 Mon Sep 17 00:00:00 2001 From: Ovear Date: Mon, 27 Sep 2021 12:47:43 +0800 Subject: [PATCH] Fix: Remove udp connection twice(#1297) #1305 --- app/proxyman/inbound/worker.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/proxyman/inbound/worker.go b/app/proxyman/inbound/worker.go index d39994e1b21..5148de00885 100644 --- a/app/proxyman/inbound/worker.go +++ b/app/proxyman/inbound/worker.go @@ -154,6 +154,11 @@ type udpConn struct { done *done.Instance uplink stats.Counter downlink stats.Counter + inactive bool +} + +func (c *udpConn) setInactive() { + c.inactive = true } func (c *udpConn) updateActivity() { @@ -317,7 +322,11 @@ func (w *udpWorker) callback(b *buf.Buffer, source net.Destination, originalDest newError("connection ends").Base(err).WriteToLog(session.ExportIDToError(ctx)) } conn.Close() - w.removeConn(id) + // conn not removed by checker TODO may be lock worker here is better + if !conn.inactive { + conn.setInactive() + w.removeConn(id) + } }() } } @@ -346,7 +355,10 @@ func (w *udpWorker) clean() error { for addr, conn := range w.activeConn { if nowSec-atomic.LoadInt64(&conn.lastActivityTime) > 8 { // TODO Timeout too small - delete(w.activeConn, addr) + if !conn.inactive { + conn.setInactive() + delete(w.activeConn, addr) + } conn.Close() } }