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

use the specified port and not a ramdom port in range[port,highest port] #4451

Closed
wants to merge 3 commits into from
Closed

Conversation

mpromonet
Copy link

What kind of change does this PR introduce? (check at least one)

  • [ x] Bugfix
  • Feature
  • Code style update
  • Refactor
  • Docs
  • Underlying tools
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

Other information:
This PR allow to fix the port running "vue serve" related in https://stackoverflow.com/questions/57536785/vue-npm-run-serve-starts-on-random-port

portfinder give a ramdom port in the range [basePort,highestPort], so asking for port 8080 result to a random port between [8080 and 40000]

@AndreasCag
Copy link

I think it is an issue with portfinder and should be fixed there.

This PR has problem - if selected port is busy, dev build would throw an error instead of selecting new port.

@mpromonet
Copy link
Author

hi @AndreasCag

There is an issue about the recent behaviour change in 1.0.22
http-party/node-portfinder#84

Sure you are right if the port is used, serve will fails.

But as option --port (or env PORT) specify a port not a range of port, so it seems strange to ask for a port and another is chosen. Maybe it could be better to extend the option to specified a range ?

Best Regards,
Michel.

@hbenl
Copy link

hbenl commented Aug 18, 2019

@AndreasCag The issue is not really in portfinder, vue-cli is relying on portfinder to try ports in ascending order, but the portfinder documentation doesn't specify the order in which ports are tried, so it is a bit foolish for vue-cli to rely on this undocumented behavior. Of course it is also foolish for portfinder to change this behavior in a minor bugfix release, I'm sure this will break a lot of other packages that also rely on the old behavior.
@mpromonet I agree that it seems strange that vue-cli chooses a different port if the specified port is used, but that seems to be the desired behavior, otherwise it would be pointless to use portfinder at all.

@BarthesSimpson
Copy link

There is a fix for this out for review in portfinder:
http-party/node-portfinder#86

@therealshark
Copy link

@AndreasCag The issue is not really in portfinder, vue-cli is relying on portfinder to try ports in ascending order, but the portfinder documentation doesn't specify the order in which ports are tried, so it is a bit foolish for vue-cli to rely on this undocumented behavior. Of course it is also foolish for portfinder to change this behavior in a minor bugfix release, I'm sure this will break a lot of other packages that also rely on the old behavior.

But it actually does specify that it will do that:
https://github.com/http-party/node-portfinder/blob/master/README.md

By default portfinder will start searching from 8000 and scan until maximum port number (40000) is reached. 40000 is the highest safe port across platforms. If you are not on OSX, you can safely override the max port up to 65535.

@hbenl
Copy link

hbenl commented Aug 19, 2019

@therealshark Oops, I missed that. Thanks for pointing it out.

@haoqunjiang
Copy link
Member

Closing this now that portfinder has fixed their bug.

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.

7 participants