tls: add host and port info to ECONNRESET errors

Add more information to the "ECONNRESET" errors generated when the
socket hang ups before establishing the secure connection.

These kind of errors are really hard to troubleshoot without this info.

PR-URL: https://github.com/nodejs/node/pull/7476
Reviewed-By: Trevor Norris <trevnorris@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Yazhong Liu <yorkiefixer@gmail.com>
This commit is contained in:
José F. Romaniello 2016-06-29 10:29:19 -03:00 committed by Tobias Nießen
parent c1c226719f
commit 3ee37329da
5 changed files with 99 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -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();
}));
}));

View File

@ -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();
}));
}));

View File

@ -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);
}));

View File

@ -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();
}));
}));