From 3c7189a3e76bb759ca9b44ce97e011de1695efa7 Mon Sep 17 00:00:00 2001 From: Ovear Date: Wed, 29 Sep 2021 22:31:59 +0800 Subject: [PATCH] Fix: Remove udp connection twice --- app/proxyman/inbound/worker.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/app/proxyman/inbound/worker.go b/app/proxyman/inbound/worker.go index 1db11a9e..4efdcbe9 100644 --- a/app/proxyman/inbound/worker.go +++ b/app/proxyman/inbound/worker.go @@ -161,6 +161,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() { @@ -328,7 +333,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) + } }() } } @@ -356,8 +365,11 @@ func (w *udpWorker) clean() error { } for addr, conn := range w.activeConn { - if nowSec-atomic.LoadInt64(&conn.lastActivityTime) > 300 { - delete(w.activeConn, addr) + if nowSec-atomic.LoadInt64(&conn.lastActivityTime) > 5*60 { // TODO Timeout too small + if !conn.inactive { + conn.setInactive() + delete(w.activeConn, addr) + } conn.Close() } }