1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 09:36:34 -05:00

Fix: Remove udp conn twice

(cherry picked from commit 75eead5a6e)

See Also: https://github.com/v2fly/v2ray-core/pull/1305
https://github.com/v2fly/v2ray-core/issues/1297
This commit is contained in:
Ovear 2021-09-27 12:47:43 +08:00 committed by Shelikhoo
parent c58811c14b
commit 9a8e113ad3
No known key found for this signature in database
GPG Key ID: AA7BC347968E7DB1

View File

@ -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()
}
}