Skip to content

Commit a5e3f15

Browse files
jfromanielloaddaleax
authored andcommitted
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: #7476 Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: Yazhong Liu <[email protected]>
1 parent e309cbc commit a5e3f15

5 files changed

+99
-0
lines changed

lib/_tls_wrap.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,10 @@ exports.connect = function(...args /* [port,] [host,] [options,] [cb] */) {
11291129
socket._hadError = true;
11301130
var error = new Error('socket hang up');
11311131
error.code = 'ECONNRESET';
1132+
error.path = options.path;
1133+
error.host = options.host;
1134+
error.port = options.port;
1135+
error.localAddress = options.localAddress;
11321136
socket.destroy(error);
11331137
}
11341138
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const net = require('net');
6+
const tls = require('tls');
7+
8+
const server = net.createServer((c) => {
9+
c.end();
10+
}).listen(common.mustCall(() => {
11+
const port = server.address().port;
12+
13+
tls.connect({
14+
port: port,
15+
localAddress: common.localhostIPv4
16+
}, common.localhostIPv4)
17+
.once('error', common.mustCall((e) => {
18+
assert.strictEqual(e.code, 'ECONNRESET');
19+
assert.strictEqual(e.path, undefined);
20+
assert.strictEqual(e.host, undefined);
21+
assert.strictEqual(e.port, port);
22+
assert.strictEqual(e.localAddress, common.localhostIPv4);
23+
server.close();
24+
}));
25+
}));
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const tls = require('tls');
6+
const net = require('net');
7+
8+
common.refreshTmpDir();
9+
10+
const server = net.createServer((c) => {
11+
c.end();
12+
}).listen(common.PIPE, common.mustCall(() => {
13+
tls.connect({ path: common.PIPE })
14+
.once('error', common.mustCall((e) => {
15+
assert.strictEqual(e.code, 'ECONNRESET');
16+
assert.strictEqual(e.path, common.PIPE);
17+
assert.strictEqual(e.port, undefined);
18+
assert.strictEqual(e.host, undefined);
19+
assert.strictEqual(e.localAddress, undefined);
20+
server.close();
21+
}));
22+
}));
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const net = require('net');
6+
const tls = require('tls');
7+
8+
const server = net.createServer((c) => {
9+
c.end();
10+
}).listen(common.mustCall(() => {
11+
const port = server.address().port;
12+
13+
const socket = new net.Socket();
14+
15+
tls.connect({ socket })
16+
.once('error', common.mustCall((e) => {
17+
assert.strictEqual(e.code, 'ECONNRESET');
18+
assert.strictEqual(e.path, undefined);
19+
assert.strictEqual(e.host, undefined);
20+
assert.strictEqual(e.port, undefined);
21+
assert.strictEqual(e.localAddress, undefined);
22+
server.close();
23+
}));
24+
25+
socket.connect(port);
26+
}));
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const net = require('net');
6+
const tls = require('tls');
7+
8+
const server = net.createServer((c) => {
9+
c.end();
10+
}).listen(common.mustCall(() => {
11+
const port = server.address().port;
12+
13+
tls.connect(port, common.localhostIPv4)
14+
.once('error', common.mustCall((e) => {
15+
assert.strictEqual(e.code, 'ECONNRESET');
16+
assert.strictEqual(e.path, undefined);
17+
assert.strictEqual(e.host, common.localhostIPv4);
18+
assert.strictEqual(e.port, port);
19+
assert.strictEqual(e.localAddress, undefined);
20+
server.close();
21+
}));
22+
}));

0 commit comments

Comments
 (0)