Skip to content

Instantly share code, notes, and snippets.



Last active Jun 15, 2017
What would you like to do?
net: EADDRINUSE is an uncatchable error
const net = require('net')
try {
net.createServer((args) => console.log(...args)).listen('hello', (error) => console.error('listen error', error))
} catch (error) {
console.error('Uncaught listen error', error)

This comment has been minimized.

Copy link
Owner Author

@stelcheck stelcheck commented Jun 15, 2017

To reproduce, run once, CTRL-C, then run once again. You should see the following output on the second run

      throw er; // Unhandled 'error' event

Error: listen EADDRINUSE hello
    at Object.exports._errnoException (util.js:1036:11)
    at exports._exceptionWithHostPort (util.js:1059:20)
    at Server._listen2 (net.js:1239:19)
    at listen (net.js:1288:10)
    at Server.listen (net.js:1377:5)
    at Object.<anonymous> (/private/tmp/listen/index.js:4:52)
    at Module._compile (module.js:556:32)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)

As you can see, the error is neither caught by the try/catch nor passed to the listen callback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment