-
Notifications
You must be signed in to change notification settings - Fork 28
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
Conversation
cc @gaearon |
796f675
to
637b0fd
Compare
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
const server = new net.Server(); | ||
|
||
server.on('error', err => { | ||
debug('listen %s error: %s', port, err); | ||
port = 0; | ||
if (port === 0) { | ||
return callback(err); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parseInt(port, 10)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default radix is 10, no need to set https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/parseInt
1.1.1 |
Thanks! |
closes #15