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

Refactor getPort to only check required port #9480

Merged
merged 1 commit into from
Mar 12, 2021
Merged

Refactor getPort to only check required port #9480

merged 1 commit into from
Mar 12, 2021

Conversation

Cartmanishere
Copy link
Contributor

Portfinder library gets port as follows --

  1. getPort({:port 0}):

    • Returns a random port.
  2. getPort({:port <non-zero>}):

    • Returns the first open port between <non-zero> and upper limit (which is 40000)
  3. getPort({:port <lower-limit>, :stopPort <upper-limit>})

    • Returns a first open port between the range <lower-limit> and <upper-limit>

In the ember script, we should only check for the specified port and not check for a range.
Hence, for a non-zero required port, we check for an open port in the range -- [portNum, portNum]
So if this port is not available, then getPort will give an exception.

If the requested port is less than 1024, then the reason for port being unavailable can be that --

  • Port is already in use
  • You do not have sufficient permissions available

So we set appropriate error message based on the requested port.

Copy link
Member

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

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

Generally seems good to me, has some linting issues to clean up.

@Cartmanishere
Copy link
Contributor Author

Fixed the linting issues. Thanks.

lib/commands/serve.js Outdated Show resolved Hide resolved
@rwjblue
Copy link
Member

rwjblue commented Mar 12, 2021

Thank you!

@rwjblue rwjblue merged commit 745f090 into ember-cli:master Mar 12, 2021
@Cartmanishere Cartmanishere deleted the get-port-refactor branch March 12, 2021 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants