mirror of
https://github.com/matrix-org/sliding-sync.git
synced 2025-03-10 13:37:11 +00:00
bugfix: fix 2 bugs with connection deletion code
- Connections are unique for the 3-uple (user, device, conneciton) IDs. The code was only checking (user, device). This means we would delete ALL connections for a device, is ANY connection expired. - ...except we wouldn't, because of the 2nd bug, which is the deletion code itself. This is missing `i--` so we will not do an ID check on the element after a deleted index. Both of these issues have now been fixed.
This commit is contained in:
parent
86f9333fdd
commit
129dea816a
@ -5,6 +5,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"golang.org/x/exp/slices"
|
||||
|
||||
"github.com/ReneKroon/ttlcache/v2"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
@ -228,10 +230,11 @@ func (m *ConnMap) closeConn(conn *Conn) {
|
||||
h := conn.handler
|
||||
conns := m.userIDToConn[conn.UserID]
|
||||
for i := 0; i < len(conns); i++ {
|
||||
if conns[i].DeviceID == conn.DeviceID {
|
||||
if conns[i].DeviceID == conn.DeviceID && conns[i].CID == conn.CID {
|
||||
// delete without preserving order
|
||||
conns[i] = conns[len(conns)-1]
|
||||
conns = conns[:len(conns)-1]
|
||||
conns[i] = nil // allow GC
|
||||
conns = slices.Delete(conns, i, i+1)
|
||||
i--
|
||||
}
|
||||
}
|
||||
m.userIDToConn[conn.UserID] = conns
|
||||
|
Loading…
x
Reference in New Issue
Block a user