Skip to content

Commit

Permalink
test: fix flaky test-tls-socket-close
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Trott authored and addaleax committed Jun 10, 2017
1 parent 3da56ac commit 4d27930
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions test/parallel/test-tls-socket-close.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@ const netServer = net.createServer((socket) => {

netSocket = socket;
}).listen(0, common.mustCall(function() {
// connect client
tls.connect({
connectClient(netServer);
}));

function connectClient(server) {
const tlsConnection = tls.connect({
host: 'localhost',
port: this.address().port,
port: server.address().port,
rejectUnauthorized: false
}).write('foo', 'utf8', common.mustCall(() => {
});

tlsConnection.write('foo', 'utf8', common.mustCall(() => {
assert(netSocket);
netSocket.setTimeout(1, common.mustCall(() => {
assert(tlsSocket);
Expand All @@ -55,4 +60,10 @@ const netServer = net.createServer((socket) => {
}, 1);
}));
}));
}));
tlsConnection.on('error', (e) => {
// Tolerate the occasional ECONNRESET.
// Ref: https://github.com/nodejs/node/issues/13184
if (e.code !== 'ECONNRESET')
throw e;
});
}

0 comments on commit 4d27930

Please sign in to comment.