mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
21fcfcdd5d
Fixes: https://github.com/nodejs/node/issues/43446 PR-URL: https://github.com/nodejs/node/pull/46781 Reviewed-By: theanarkh <theratliter@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
30 lines
685 B
JavaScript
30 lines
685 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const net = require('net');
|
|
|
|
function barrier(count, cb) {
|
|
return function() {
|
|
if (--count === 0)
|
|
cb();
|
|
};
|
|
}
|
|
|
|
const server = net.createServer();
|
|
server.listen(0, common.mustCall(function() {
|
|
const port = server.address().port;
|
|
const conn = net.createConnection(port);
|
|
const connok = barrier(2, () => conn.resetAndDestroy());
|
|
conn.on('close', common.mustCall());
|
|
server.on('connection', (socket) => {
|
|
connok();
|
|
socket.on('error', common.expectsError({
|
|
code: 'ECONNRESET',
|
|
message: 'read ECONNRESET',
|
|
name: 'Error'
|
|
}));
|
|
server.close();
|
|
});
|
|
conn.on('connect', connok);
|
|
}));
|