From 9e5e0332b50ea93a6c6830575a0a29e6c80df0c6 Mon Sep 17 00:00:00 2001 From: Ash Logan Date: Fri, 3 Jan 2025 18:30:58 +1100 Subject: [PATCH] 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. --- prudp_endpoint.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prudp_endpoint.go b/prudp_endpoint.go index b198d19..c1a2a0f 100644 --- a/prudp_endpoint.go +++ b/prudp_endpoint.go @@ -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 }