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:
parent
c1c226719f
commit
3ee37329da
@ -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);
|
||||
}
|
||||
}
|
||||
|
25
test/parallel/test-tls-wrap-econnreset-localaddress.js
Normal file
25
test/parallel/test-tls-wrap-econnreset-localaddress.js
Normal 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();
|
||||
}));
|
||||
}));
|
22
test/parallel/test-tls-wrap-econnreset-pipe.js
Normal file
22
test/parallel/test-tls-wrap-econnreset-pipe.js
Normal 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();
|
||||
}));
|
||||
}));
|
26
test/parallel/test-tls-wrap-econnreset-socket.js
Normal file
26
test/parallel/test-tls-wrap-econnreset-socket.js
Normal 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);
|
||||
}));
|
22
test/parallel/test-tls-wrap-econnreset.js
Normal file
22
test/parallel/test-tls-wrap-econnreset.js
Normal 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();
|
||||
}));
|
||||
}));
|
Loading…
x
Reference in New Issue
Block a user