Skip to content

Remember randomly selected ports, and don't reuse them #5685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

shauns
Copy link
Contributor

@shauns shauns commented Apr 23, 2025

WHY are these changes introduced?

To prevent port conflicts when multiple processes request random TCP ports in quick succession. If a caller doesn't use a port immediately, a duplicate random port can be chosen.

WHAT is this pull request doing?

Enhances the getAvailableTCPPort function to track previously obtained random ports and ensure they aren't reused within the same process. This is accomplished by:

  1. Adding a obtainedRandomPorts Set to keep track of ports that have been assigned
  2. Adding logic to check if a random port has already been obtained and retry if necessary
  3. Adding the obtained port to the tracking Set before returning it

Added a test case to verify that random ports are not reused.

Copy link
Contributor Author

shauns commented Apr 23, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@shauns shauns marked this pull request as ready for review April 23, 2025 12:16
@shauns shauns requested a review from a team as a code owner April 23, 2025 12:16
Copy link
Contributor

We detected some changes at packages/*/src and there are no updates in the .changeset.
If the changes are user-facing, run "pnpm changeset add" to track your changes and include them in the next release CHANGELOG.

Copy link
Contributor

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
76.72% (+0.02% 🔼)
9513/12399
🟡 Branches
71.85% (+0.03% 🔼)
4678/6511
🟡 Functions
76.47% (+0.01% 🔼)
2464/3222
🟡 Lines
77.25% (+0.02% 🔼)
8993/11641

Test suite run success

2218 tests passing in 966 suites.

Report generated by 🧪jest coverage report action from 539c002

@shauns shauns added this pull request to the merge queue Apr 23, 2025
Merged via the queue into main with commit 0ba9de0 Apr 23, 2025
31 checks passed
@shauns shauns deleted the shauns/04-23-remember_randomly_selected_ports_and_don_t_reuse_them branch April 23, 2025 14:55
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.

2 participants