fix(endpoint): Check PID invariant in FindConnectionByPID

An expected invariant of this system is that StateConnected connections also have a PID, and other states do *not* have a PID.

While any code that breaks this invariant is buggy, we can still make FindConnectionByPID resilient to this to prevent that type of bug from taking the whole server down.

That type of bug can still be detected through explicit testing of the Connections map.
This commit is contained in:
Ash Logan 2025-01-03 18:30:58 +11:00
parent fbe2b91e75
commit 9e5e0332b5

View file

@ -708,7 +708,7 @@ func (pep *PRUDPEndPoint) FindConnectionByPID(pid uint64) *PRUDPConnection {
var connection *PRUDPConnection
pep.Connections.Each(func(discriminator string, pc *PRUDPConnection) bool {
if pc.pid.Value() == pid {
if pc.pid.Value() == pid && pc.ConnectionState == StateConnected {
connection = pc
return true
}