Skip to content

Commit

Permalink
fix(endpoint): Check PID invariant in FindConnectionByPID
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ashquarky committed Jan 4, 2025
1 parent fbe2b91 commit 9e5e033
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion prudp_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 9e5e033

Please sign in to comment.