Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix flaky test-net-write-after-close #14361

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions test/parallel/test-net-write-after-close.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,31 @@

'use strict';
const common = require('../common');

const net = require('net');

let serverSocket;

const server = net.createServer(common.mustCall(function(socket) {
serverSocket = socket;

socket.resume();

socket.on('error', common.mustCall(function(error) {
console.error('got error, closing server', error);
console.error('received error as expected, closing server', error);
server.close();
}));

setTimeout(common.mustCall(function() {
console.error('about to try to write');
socket.write('test', common.mustCall());
}), 250);
}));

server.listen(0, function() {
const client = net.connect(this.address().port, function() {
// cliend.end() will close both the readable and writable side
// of the duplex because allowHalfOpen defaults to false.
// Then 'end' will be emitted when it receives a FIN packet from
// the other side.
client.on('end', common.mustCall(() => {
serverSocket.write('test', common.mustCall());
}));
client.end();
});
});