Skip to content

Commit

Permalink
tls: add host and port info to ECONNRESET errors
Browse files Browse the repository at this point in the history
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: #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>
  • Loading branch information
jfromaniello authored and addaleax committed Jul 11, 2017
1 parent 74741fa commit e2d3254
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
25 changes: 25 additions & 0 deletions test/parallel/test-tls-wrap-econnreset-localaddress.js
Original file line number Diff line number Diff line change
@@ -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 changes: 22 additions & 0 deletions test/parallel/test-tls-wrap-econnreset-pipe.js
Original file line number Diff line number Diff line change
@@ -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 changes: 26 additions & 0 deletions test/parallel/test-tls-wrap-econnreset-socket.js
Original file line number Diff line number Diff line change
@@ -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 changes: 22 additions & 0 deletions test/parallel/test-tls-wrap-econnreset.js
Original file line number Diff line number Diff line change
@@ -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();
}));
}));

0 comments on commit e2d3254

Please sign in to comment.