Skip to content

Commit

Permalink
test: fix test-socket-write-after-fin-error
Browse files Browse the repository at this point in the history
The `'error'` event is not emitted because the socket is already
destroyed when `socket.write()` is called. Use the `socket.write()`
callback instead.

PR-URL: #42340
Refs: #42340 (comment)
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
lpinca authored and RafaelGSS committed Nov 10, 2022
1 parent 2fcf851 commit 43db0fb
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions test/parallel/test-socket-write-after-fin-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ let gotServerError = false;

const server = net.createServer(function(sock) {
sock.setEncoding('utf8');
sock.on('error', function(er) {
console.error(`${er.code}: ${er.message}`);
gotServerError = er;
});
sock.on('error', function() {});

sock.on('data', function(c) {
serverData += c;
});
sock.on('end', function() {
gotServerEnd = true;
setImmediate(() => {
sock.write(serverData);
sock.write(serverData, function(er) {
console.error(`${er.code}: ${er.message}`);
gotServerError = er;
});
sock.end();
});
});
Expand Down

0 comments on commit 43db0fb

Please sign in to comment.