Skip to content
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

fix: explicit port/portRange even if random is true #69

Closed
wants to merge 1 commit into from

Conversation

peterroe
Copy link

πŸ”— Linked issue

#65

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@peterroe peterroe changed the title fix: explicit port/portRange even if randon is true fix: explicit port/portRange even if random is true Oct 22, 2023
const j = Math.floor(Math.random() * (i + 1));
[r[i], r[j]] = [r[j], r[i]];
}
}
Copy link
Member

Choose a reason for hiding this comment

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

We should depend on OS behavior for choosing a random port.

Copy link
Author

@peterroe peterroe Oct 23, 2023

Choose a reason for hiding this comment

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

I tried to find a solution but I failed

The port exposed by net.createServer().listen(0) depends on the internal method of node. https://github.com/nodejs/node/blob/04f9385311d7bc7df0beabf10541e599c2592c6f/lib/net.js#L1924-L1934

There seems to be no good way to have the system randomly select a port within a certain range

And I tried calling the listen(0) method countless times, but the returned random port still failed to hit a certain range that I wanted.

@pi0
Copy link
Member

pi0 commented Jan 9, 2024

Thanks for PR. linked issue should be resolved by cd4acec in next release.

@pi0 pi0 closed this Jan 9, 2024
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.

None yet

2 participants