`ENETUNREACH` not handled for `http.request` in 7.10.0
- Version: 7.10.0
- Platform: Linux
- Subsystem: http
As the title says that error is not delivered via the returned event emitter, an exception is thrown instead. Other errors are properly handled, e.g., using {port: 0} which causes ECONNREFUSED. Also the net subsystem doesn't seem to be affected when I try with net.connect using the same options.
Here is the snippet to reproduce it:
const http = require('http'); const request = http.request({host: '255.255.255.255'}); request.on('error', console.error);
Incorrect behavior
$ nvm use 7.10.0 Now using node v7.10.0 $ node issue.js events.js:163 throw er; // Unhandled 'error' event ^ Error: connect ENETUNREACH 255.255.255.255:80 - Local (0.0.0.0:0) at Object.exports._errnoException (util.js:1050:11) at exports._exceptionWithHostPort (util.js:1073:20) at internalConnect (net.js:889:16) at lookupAndConnect (net.js:977:5) at Socket.realConnect (net.js:945:5) at Agent.connect [as createConnection] (net.js:77:22) at Agent.createSocket (_http_agent.js:195:26) at Agent.addRequest (_http_agent.js:157:10) at new ClientRequest (_http_client.js:212:16) at Object.request (http.js:26:10)
Expected behavior
$ nvm use 7.9.0 Now using node v7.9.0 $ node issue.js { Error: connect ENETUNREACH 255.255.255.255:80 - Local (0.0.0.0:0) at Object.exports._errnoException (util.js:1050:11) at exports._exceptionWithHostPort (util.js:1073:20) at internalConnect (net.js:894:16) at net.js:980:9 at _combinedTickCallback (internal/process/next_tick.js:73:7) at process._tickCallback (internal/process/next_tick.js:104:9) at Module.runMain (module.js:607:11) at run (bootstrap_node.js:423:7) at startup (bootstrap_node.js:147:9) at bootstrap_node.js:538:3 code: 'ENETUNREACH', errno: 'ENETUNREACH', syscall: 'connect', address: '255.255.255.255', port: 80 }