You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
doc issue: socket server 'error' event: 'close' is not called as described in doc. #9710
Platform:Darwin p14010112-no-MacBook-Pro.local 15.6.0 Darwin Kernel Version 15.6.0: Thu Jun 23 18:25:34 PDT 2016; root:xnu-3248.60.10~1/RELEASE_X86_64 x86_64
Subsystem:
I am curious that should i call server.close in server.on('error'...) handler?
Event: 'error'#
<Error>
Emitted when an error occurs. The 'close' event will be called directly following this event. See example in discussion of server.listen.
But in fact, the 'close' event does not happen after error.
This is my test.js which try to listen a privileged port 80, cause an EACCESS error and exit.
To ensure the close event can be caught before process exit, i set up a 1 second timer so process will keep alive in 1 second.
But still, the close event does not happen.
If i add this.close() in error handler, then the 'close' does happen.
According to another doc about server.listen, obviously node.js does not call close on error, at least for EADDRINUSE.
server.on('error', (e) => {
if (e.code == 'EADDRINUSE') {
console.log('Address in use, retrying...');
setTimeout(() => {
server.close(); //see here please. If it is auto closed, why need this?
server.listen(PORT, HOST);
}, 1000);
}
});
So the document is contradictory, it should be noted that 'close' will not be called automatically.
Activity
mscdex commentedon Nov 20, 2016
It may have just been copied from the
net.Socketdocumentation, where'close'is always emitted (after'error'and/or'end').krydos commentedon Feb 2, 2017
@mscdex Is it ok to just remove everything except
Emitted when an error occurs.?If yes I can prepare pull request. If no, I still can prepare pull request with something else :)
jjqq2013 commentedon Feb 3, 2017
@krydos no, i think the doc should insert a word "not"
=>
jjqq2013 commentedon Feb 3, 2017
@krydos i'v made a pull request.
doc: add comment for net.Server's error event
doc: add comment for net.Server's error event
doc: add comment for net.Server's error event
doc: add comment for net.Server's error event
doc: add comment for net.Server's error event
doc: add comment for net.Server's error event