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

Avoid breaking existing consumers who use startPort >= 40000 #86

Closed
wants to merge 17 commits into from

Conversation

BarthesSimpson
Copy link
Contributor

@BarthesSimpson BarthesSimpson commented Aug 17, 2019

This would fix the issue identified in #85. If there is an existing consumer who uses getPort with a startPort greater than 40000, instead of throwing an Error this will log a warning to the console and bump the stopPort up to 65535 (i.e. behave the same as before exports.highestPort was reduced to 40000).

An error is still thrown if the stopPort is lower than the stopPort when both of these values are below 40000.

@BarthesSimpson BarthesSimpson marked this pull request as ready for review August 17, 2019 18:51
@BarthesSimpson
Copy link
Contributor Author

Updated to also address #84. By default, getPort will use the previous sequential scan. If useRandom: true is passed inside the options, then the random search will be used instead.

@jaredjj3
Copy link

LGTM

Thank you for working on this PR.

Copy link

@jelhan jelhan left a comment

Choose a reason for hiding this comment

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

Looks good and seems to fix both issues encountered in Ember CLI.

lib/portfinder.js Outdated Show resolved Hide resolved
lib/portfinder.js Outdated Show resolved Hide resolved
@jelhan
Copy link

jelhan commented Aug 18, 2019

I see some strange behavior for port = 40000. I'm not 100%ly sure yet if this is a bug or just coincidence. If calling ember serve --port 40000, which should equal getPort({ port: 40000 }) I'm seeing No open ports found in between 40000 and 40000. It's working fine for 39999 and 40001. Haven't have the time yet to follow the investigate the control flow for that edge case yet.

@BarthesSimpson
Copy link
Contributor Author

I think that's because the startPort:stopPort interval is closed, so if startPort and stopPort are the same, no port will be checked. Let me double check that the interval is supposed to be open and then I can update this PR accordingly (later today).

@BarthesSimpson
Copy link
Contributor Author

OK, yeah the interval should be open, not closed. Will update now.

@haoqunjiang
Copy link

Ping @eriktrom. Sorry to bother you, but is there any chance to get this PR merged soon? Lots of downstream repositories are relying on this feature to work correctly.

@Ten0
Copy link

Ten0 commented Aug 19, 2019

Ping @eriktrom. Sorry to bother you, but is there any chance to get this PR merged soon? Lots of downstream repositories are relying on this feature to work correctly.

+1. With 877 dependant packages and 4 685 655 weekly downloads, this as-patch breaking change that prevents port choice is breaking so many systems right now and shouldn't stay broken for so long.

@soloitguy
Copy link

Downgrading to 1.0.21 explicitly is a temporary fix. Our outage was a bit too long to wait for the PR.

@eriktrom
Copy link
Member

@BarthesSimpson - thanks - i will take a closer look tonight, tomorrow and follow up.

For today, i rolled back to v1.0.21 (as v1.0.23)

@eriktrom
Copy link
Member

@BarthesSimpson - I feel like we should consider an option that does not directly modify the main repo -- maybe another export getRandomPort which uses the in place randomization (port 0 actually may do this automatically, it does in ember-cli, it's been years but I believe its a straight passthrough to portfinder port: 0 or port: undefined.

I'm very hesitant to release another version that is not a semver major bump unless we can guarantee that changes are strictly additive.

Thoughts?

@eriktrom
Copy link
Member

If useRandom: true is passed inside the options, then the random search will be used instead.

The only issue here is that, for example, lets say you start 2 test servers inside ember cli - if we pass useRandom: true then we have detect the os arch to be darwin - which seems reasonable - unless via docker or minikube your actually using hyperkit - with port forwarding - to be more clear on the port 40,000-60,000 thing - the error is a permission error - binding to the socket works, using it throws a permission error

b/c of matrix of use cases upstream are very high, this single example should help explain my concern.

fixing for ember-cli is one thing, for firebase, circleci and other tools that depend on the current behavior 'as is' -- i think we make a new method or (if the code was cleaner) an extension poiint, but new method more likely in this case

@BarthesSimpson
Copy link
Contributor Author

Sure - I'll take another look this weekend and see if I can find a good approach for adding a getRandomPort export.

@eriktrom
Copy link
Member

eriktrom commented Sep 4, 2019

@BarthesSimpson - see #91 for thoughts on releasing changes to portfinder moving forward - mostly that we should only do so if we do a semver major release, reducing exposure to how this library has been used by different consumers over the past many years.

If we go that route, we can consider adding deprecation warning to v1.x that would not take effect until v3.x - although someone would need to take the lead on this as I'm involved in the depths of a few other topics right now - just fyi - open a meta ticket if you want to start a discussion outside this thread regarding such things

I'm going to close this issue and link to it from a clean issue, so we don't spam

@eriktrom
Copy link
Member

eriktrom commented Sep 4, 2019

@BarthesSimpson - #92 is a meta issue on a semver major that I would feel comfortable releasing these changes to. Re-opening, with 2.x tag.

@eriktrom eriktrom reopened this Sep 4, 2019
@eriktrom eriktrom added the 2x label Sep 4, 2019
@eriktrom
Copy link
Member

FYI: if interest remains in merging this (w/ the randomization feature via @BarthesSimpson original work) see #105 and vote. I'm taking a quick pulse of the traction it would garner if made possible to you and others.

@eriktrom
Copy link
Member

closing to cleanup issue list, comments or questions still welcome, if needed

consolidated via #99

@eriktrom eriktrom closed this Jul 29, 2020
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.

8 participants