fix: udpSessionManager.mutex reentrant by cleanup

This commit is contained in:
Haruue 2024-10-04 16:33:41 +08:00
parent 931fc2fdb2
commit dc023ae13a
No known key found for this signature in database
GPG key ID: F6083B28CBCBC148

View file

@ -262,16 +262,21 @@ func (m *udpSessionManager) idleCleanupLoop(stopCh <-chan struct{}) {
func (m *udpSessionManager) cleanup(idleOnly bool) {
// We use RLock here as we are only scanning the map, not deleting from it.
m.mutex.RLock()
defer m.mutex.RUnlock()
timeoutEntry := make([]*udpSessionEntry, 0, len(m.m))
m.mutex.RLock()
now := time.Now()
for _, entry := range m.m {
if !idleOnly || now.Sub(entry.Last.Get()) > m.idleTimeout {
entry.MarkTimeout()
// Entry will be removed by its ExitFunc.
timeoutEntry = append(timeoutEntry, entry)
}
}
m.mutex.RUnlock()
for _, entry := range timeoutEntry {
entry.MarkTimeout()
// Entry will be removed by its ExitFunc.
}
}
func (m *udpSessionManager) feed(msg *protocol.UDPMessage) {