Skip to content

Fix unnecessary delay in the port tracking loop - #41472

Open
Feng Wang (chemwolf6922) wants to merge 2 commits into
masterfrom
user/chemwolf6922/fix-unnecessary-delay-in-bind-seccomp-handling
Open

Fix unnecessary delay in the port tracking loop#41472
Feng Wang (chemwolf6922) wants to merge 2 commits into
masterfrom
user/chemwolf6922/fix-unnecessary-delay-in-bind-seccomp-handling

Conversation

@chemwolf6922

@chemwolf6922 Feng Wang (chemwolf6922) commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Summary of the Pull Request

Before this change, an additional 10ms delay was added in the port tracker loop presumably to make the main loop slower than the worker loop. So, the worker result does not get super dated. This is not reliable. And the 10ms delay also slows down every consecutive bind call.

This PR refactors the thread synchronization method. So, the timing between those two loops is more deterministic. And removes the performance penalty for all bind calls.

PR Checklist

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

Measure 100 consecutive bind calls for different AF.

Type Before After
netlink 1030ms 56ms
UDS 1008ms 57ms
UDP bind 0 2174ms 1135ms

The extra UDP bind 0 time is from the getsockname poll. Which is required.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes an unnecessary per-bind() delay in the Linux init port-tracking path by replacing the prior timeout/promise-based synchronization with a single event stream (seccomp notifications + periodic port refresh results), aiming to make the coordination between the main loop and the refresh worker deterministic and faster.

Changes:

  • Refactored GnsPortTracker to use WaitableValue<std::variant<...>> for event delivery and a separate WaitableValue<bool> for refresh acknowledgements.
  • Removed the previous std::promise/std::future polling and the associated short poll timeouts from the main loop.
  • Updated WaitableValue to support move semantics for posted/retrieved values.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/linux/init/waitablevalue.h Switches post/get/try_get to move-based storage/return to avoid unnecessary copies.
src/linux/init/GnsPortTracker.h Replaces promise/future refresh plumbing with a TrackerEvent variant and new waitable signals.
src/linux/init/GnsPortTracker.cpp Refactors the main loop into an event-driven design and removes timeout-based polling delays.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/linux/init/GnsPortTracker.cpp Outdated
Copilot AI review requested due to automatic review settings August 28, 2026 09:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bind() takes ~10 ms for every socket family under WSL2, independent of networking mode

2 participants