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: try to use next available port #16

Merged
merged 2 commits into from
Mar 17, 2017
Merged

fix: try to use next available port #16

merged 2 commits into from
Mar 17, 2017

Conversation

fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Mar 17, 2017

closes #15

@mention-bot
Copy link

@fengmk2, thanks for your PR! By analyzing the history of the files in this pull request, we identified @xudafeng to be a potential reviewer.

@fengmk2
Copy link
Member Author

fengmk2 commented Mar 17, 2017

cc @gaearon

@codecov
Copy link

codecov bot commented Mar 17, 2017

Codecov Report

Merging #16 into master will decrease coverage by 5.71%.
The diff coverage is 87.5%.

@@            Coverage Diff             @@
##           master      #16      +/-   ##
==========================================
- Coverage     100%   94.28%   -5.72%     
==========================================
  Files           2        2              
  Lines          25       35      +10     
==========================================
+ Hits           25       33       +8     
- Misses          0        2       +2
Impacted Files Coverage Δ
lib/detect-port.js 94.11% <87.5%> (-5.89%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update de63f55...22b2e33. Read the comment docs.

const server = new net.Server();

server.on('error', err => {
debug('listen %s error: %s', port, err);
port = 0;
if (port === 0) {
return callback(err);
Copy link
Member

Choose a reason for hiding this comment

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

Why not try another random port?

Copy link
Member Author

@fengmk2 fengmk2 Mar 17, 2017

Choose a reason for hiding this comment

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

random port won't error on normal case. If listen random port error happen, it's hard to try again, maybe "open file handles" is full on that time.

Copy link
Member

Choose a reason for hiding this comment

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

This line is not covered

Copy link
Member Author

Choose a reason for hiding this comment

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

It's hard to mock this error, ignore it for now.

@@ -8,26 +8,40 @@ module.exports = (port, callback) => {
callback = port;
port = null;
}
port = parseInt(port) || 0;
Copy link
Member

Choose a reason for hiding this comment

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

parseInt(port, 10)

Copy link
Member Author

Choose a reason for hiding this comment

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

@fengmk2 fengmk2 merged commit 817105e into master Mar 17, 2017
@fengmk2 fengmk2 deleted the try-to-use-next-port branch March 17, 2017 15:46
@fengmk2
Copy link
Member Author

fengmk2 commented Mar 17, 2017

1.1.1

@gaearon
Copy link
Collaborator

gaearon commented Mar 17, 2017

Thanks!

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.

Is it possible to use next available port?
5 participants