SS2022 inbound: Fix data races and duplicate acceptance when decoding one UDP session concurrently

Packets of one client session can be processed by two inbound workers at
the same time (e.g. the client's old and new source address after a NAT
rebinding). The sliding window was checked and updated in two separate
critical sections, and clientBodyCipher and the session's User were read
without the lock, so the same packet ID could be accepted more than once
and go test -race reported data races.

Re-check the window and publish the cached body cipher in one critical
section after the packet is fully validated, and always initialize the
session's User under the lock.
This commit is contained in:
Roman Rublev
2026-10-18 16:28:31 +03:00
parent 92ccc939aa
commit 8d0a7cf856
5 changed files with 97 additions and 22 deletions
+3 -5
View File
@@ -162,13 +162,11 @@ func (i *Inbound) processUDP(ctx context.Context, conn stat.Connection, dispatch
}
sessionItem := i.udpCodec.GetSession(decoded.SessionID)
sessionItem.Lock()
if sessionItem.User == nil {
sessionItem.Lock()
if sessionItem.User == nil {
sessionItem.User = i.user
}
sessionItem.Unlock()
sessionItem.User = i.user
}
sessionItem.Unlock()
link := sessionItem.link.Load()
if link != nil {
sessionItem.UpdateConn(conn)