Skip to content

Commit 8de9ffd

Browse files
committed
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.) Fixes: nodejs#13184
1 parent 6b07065 commit 8de9ffd

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

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

Lines changed: 16 additions & 5 deletions
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)