diff --git a/lib/net.js b/lib/net.js index 54ddaa3b403044..6c2bf568758ed6 100644 --- a/lib/net.js +++ b/lib/net.js @@ -410,6 +410,8 @@ function writeAfterFIN(chunk, encoding, cb) { if (typeof cb === 'function') { defaultTriggerAsyncIdScope(this[async_id_symbol], process.nextTick, cb, er); } + + return false; } Socket.prototype.setTimeout = setStreamTimeout; diff --git a/test/parallel/test-net-write-after-end-nt.js b/test/parallel/test-net-write-after-end-nt.js index 3f93b444f4cb36..d2f7c5c212ca0e 100644 --- a/test/parallel/test-net-write-after-end-nt.js +++ b/test/parallel/test-net-write-after-end-nt.js @@ -4,7 +4,7 @@ const common = require('../common'); const assert = require('assert'); const net = require('net'); -const { mustCall } = common; +const { expectsError, mustCall } = common; // This test ensures those errors caused by calling `net.Socket.write()` // after sockets ending will be emitted in the next tick. @@ -18,7 +18,13 @@ const server = net.createServer(mustCall((socket) => { server.close(); })); client.on('end', mustCall(() => { - client.write('hello', mustCall()); + const ret = client.write('hello', expectsError({ + code: 'EPIPE', + message: 'This socket has been ended by the other party', + type: Error + })); + + assert.strictEqual(ret, false); assert(!hasError, 'The error should be emitted in the next tick.'); })); client.end();