Skip to content

Commit 4d27930

Browse files
Trottaddaleax
authored andcommitted
test: fix flaky test-tls-socket-close
Add error listener to ignore `ECONNRESET`. Makes test reliable while it still segfaults (as expected) on Node.js 7.7.3. It might not be possible to eliminate the probable race causing `ECONNRESET` without also eliminating the required segfault-inducing part of the test. (Or maybe it's totally possible. If you figure it out, hey cool, submit a pull request.) PR-URL: #13529 Fixes: #13184 Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 3da56ac commit 4d27930

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

test/parallel/test-tls-socket-close.js

+16-5
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,17 @@ const netServer = net.createServer((socket) => {
3232

3333
netSocket = socket;
3434
}).listen(0, common.mustCall(function() {
35-
// connect client
36-
tls.connect({
35+
connectClient(netServer);
36+
}));
37+
38+
function connectClient(server) {
39+
const tlsConnection = tls.connect({
3740
host: 'localhost',
38-
port: this.address().port,
41+
port: server.address().port,
3942
rejectUnauthorized: false
40-
}).write('foo', 'utf8', common.mustCall(() => {
43+
});
44+
45+
tlsConnection.write('foo', 'utf8', common.mustCall(() => {
4146
assert(netSocket);
4247
netSocket.setTimeout(1, common.mustCall(() => {
4348
assert(tlsSocket);
@@ -55,4 +60,10 @@ const netServer = net.createServer((socket) => {
5560
}, 1);
5661
}));
5762
}));
58-
}));
63+
tlsConnection.on('error', (e) => {
64+
// Tolerate the occasional ECONNRESET.
65+
// Ref: https://github.com/nodejs/node/issues/13184
66+
if (e.code !== 'ECONNRESET')
67+
throw e;
68+
});
69+
}

0 commit comments

Comments
 (0)