diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index eba8aada150bd2..aba633a8ac2080 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -1129,6 +1129,10 @@ exports.connect = function(...args /* [port,] [host,] [options,] [cb] */) { socket._hadError = true; var error = new Error('socket hang up'); error.code = 'ECONNRESET'; + error.path = options.path; + error.host = options.host; + error.port = options.port; + error.localAddress = options.localAddress; socket.destroy(error); } } diff --git a/test/parallel/test-tls-wrap-econnreset-localaddress.js b/test/parallel/test-tls-wrap-econnreset-localaddress.js new file mode 100644 index 00000000000000..981e57248aee03 --- /dev/null +++ b/test/parallel/test-tls-wrap-econnreset-localaddress.js @@ -0,0 +1,25 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const net = require('net'); +const tls = require('tls'); + +const server = net.createServer((c) => { + c.end(); +}).listen(common.mustCall(() => { + const port = server.address().port; + + tls.connect({ + port: port, + localAddress: common.localhostIPv4 + }, common.localhostIPv4) + .once('error', common.mustCall((e) => { + assert.strictEqual(e.code, 'ECONNRESET'); + assert.strictEqual(e.path, undefined); + assert.strictEqual(e.host, undefined); + assert.strictEqual(e.port, port); + assert.strictEqual(e.localAddress, common.localhostIPv4); + server.close(); + })); +})); diff --git a/test/parallel/test-tls-wrap-econnreset-pipe.js b/test/parallel/test-tls-wrap-econnreset-pipe.js new file mode 100644 index 00000000000000..5925d65658e7cc --- /dev/null +++ b/test/parallel/test-tls-wrap-econnreset-pipe.js @@ -0,0 +1,22 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const tls = require('tls'); +const net = require('net'); + +common.refreshTmpDir(); + +const server = net.createServer((c) => { + c.end(); +}).listen(common.PIPE, common.mustCall(() => { + tls.connect({ path: common.PIPE }) + .once('error', common.mustCall((e) => { + assert.strictEqual(e.code, 'ECONNRESET'); + assert.strictEqual(e.path, common.PIPE); + assert.strictEqual(e.port, undefined); + assert.strictEqual(e.host, undefined); + assert.strictEqual(e.localAddress, undefined); + server.close(); + })); +})); diff --git a/test/parallel/test-tls-wrap-econnreset-socket.js b/test/parallel/test-tls-wrap-econnreset-socket.js new file mode 100644 index 00000000000000..ba7511c1944ca6 --- /dev/null +++ b/test/parallel/test-tls-wrap-econnreset-socket.js @@ -0,0 +1,26 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const net = require('net'); +const tls = require('tls'); + +const server = net.createServer((c) => { + c.end(); +}).listen(common.mustCall(() => { + const port = server.address().port; + + const socket = new net.Socket(); + + tls.connect({ socket }) + .once('error', common.mustCall((e) => { + assert.strictEqual(e.code, 'ECONNRESET'); + assert.strictEqual(e.path, undefined); + assert.strictEqual(e.host, undefined); + assert.strictEqual(e.port, undefined); + assert.strictEqual(e.localAddress, undefined); + server.close(); + })); + + socket.connect(port); +})); diff --git a/test/parallel/test-tls-wrap-econnreset.js b/test/parallel/test-tls-wrap-econnreset.js new file mode 100644 index 00000000000000..07fdaf6b221b55 --- /dev/null +++ b/test/parallel/test-tls-wrap-econnreset.js @@ -0,0 +1,22 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const net = require('net'); +const tls = require('tls'); + +const server = net.createServer((c) => { + c.end(); +}).listen(common.mustCall(() => { + const port = server.address().port; + + tls.connect(port, common.localhostIPv4) + .once('error', common.mustCall((e) => { + assert.strictEqual(e.code, 'ECONNRESET'); + assert.strictEqual(e.path, undefined); + assert.strictEqual(e.host, common.localhostIPv4); + assert.strictEqual(e.port, port); + assert.strictEqual(e.localAddress, undefined); + server.close(); + })); +}));