From 84da857dcd2c186f7d2f571cdb6dcd0e86feb32c Mon Sep 17 00:00:00 2001 From: Ovear Date: Mon, 27 Sep 2021 12:47:43 +0800 Subject: [PATCH 1/2] Fix: Remove udp conn twice --- app/proxyman/inbound/worker.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app/proxyman/inbound/worker.go b/app/proxyman/inbound/worker.go index 09574a976d8..2242da2d008 100644 --- a/app/proxyman/inbound/worker.go +++ b/app/proxyman/inbound/worker.go @@ -153,6 +153,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() { @@ -315,7 +320,13 @@ 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) + } else { + newError("connection already removed by checker: ", conn).AtDebug().WriteToLog(session.ExportIDToError(ctx)) + } }() } } @@ -344,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() } } From c6a4e3a00aee7d9f7a1f0150b7fc6825e68d7e97 Mon Sep 17 00:00:00 2001 From: Ovear Date: Mon, 27 Sep 2021 22:20:23 +0800 Subject: [PATCH 2/2] Remove unnecessary log. --- app/proxyman/inbound/worker.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/proxyman/inbound/worker.go b/app/proxyman/inbound/worker.go index 2242da2d008..eac983e7e9e 100644 --- a/app/proxyman/inbound/worker.go +++ b/app/proxyman/inbound/worker.go @@ -324,8 +324,6 @@ func (w *udpWorker) callback(b *buf.Buffer, source net.Destination, originalDest if !conn.inactive { conn.setInactive() w.removeConn(id) - } else { - newError("connection already removed by checker: ", conn).AtDebug().WriteToLog(session.ExportIDToError(ctx)) } }() }