Skip to content

Commit

Permalink
Fix: Remove udp connection twice(v2fly#1297) v2fly#1305
Browse files Browse the repository at this point in the history
  • Loading branch information
Ovear authored and nekohasekai committed Sep 29, 2021
1 parent 6aa81d6 commit 86b1cca
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions app/proxyman/inbound/worker.go
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
}
}()
}
}
Expand Down Expand Up @@ -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()
}
}
Expand Down

0 comments on commit 86b1cca

Please sign in to comment.