Fix port tracking for implicit binds resulting from accept() calls#40287
Fix port tracking for implicit binds resulting from accept() calls#40287FetoiuCatalin wants to merge 4 commits intomasterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the Linux-side GnsPortTracker port refresh logic so that tracked port allocations are not deallocated while any active socket is still using the same (protocol, port), including sockets that implicitly “inherit” the local port via accept().
Changes:
- Adjust
OnRefreshAllocatedPortsto consider any active socket using the same protocol+port as a match (not requiring an exactPortAllocationmatch). - Add explanatory comments clarifying why implicit binds (e.g., accepted sockets) must keep allocations alive.
| return p.Port == it->first.Port && p.Protocol == it->first.Protocol; | ||
| }; | ||
|
|
||
| if (std::find_if(Ports.begin(), Ports.end(), matchCondition) == Ports.end()) |
There was a problem hiding this comment.
This new use of std::find_if requires <algorithm> to be included directly in this translation unit (or in a header it includes). Relying on transitive standard-library includes is non-portable and can break builds on other toolchains; add #include <algorithm> near the top of this file.
| return p.Port == it->first.Port && p.Protocol == it->first.Protocol; | ||
| }; | ||
|
|
||
| if (std::find_if(Ports.begin(), Ports.end(), matchCondition) == Ports.end()) |
|
todo add automated tests for the scenario of opening listen socket, accepting a connection on that socket, closing the listen socket, verify the traffic still flows on the connection socket |
Summary of the Pull Request
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed