diff options
author | Luigi Pinca <luigipinca@gmail.com> | 2019-05-31 20:36:23 +0200 |
---|---|---|
committer | Daniel Bevenius <daniel.bevenius@gmail.com> | 2019-06-04 06:02:58 +0200 |
commit | 714a32c41f7cedec76cd7a237ac12f4cee7fcf85 (patch) | |
tree | de324195811545e2cb71fd7717d6e69b86529449 | |
parent | d9117896a6fd4e5fb0edd0f90be9c7a01649ff3f (diff) | |
download | node-new-714a32c41f7cedec76cd7a237ac12f4cee7fcf85.tar.gz |
net: make writeAfterFIN() return false
If `false` is not returned a readable stream piped into the socket
might continue reading indefinitely until the process goes out of
memory.
PR-URL: https://github.com/nodejs/node/pull/27996
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
-rw-r--r-- | lib/net.js | 2 | ||||
-rw-r--r-- | test/parallel/test-net-write-after-end-nt.js | 10 |
2 files changed, 10 insertions, 2 deletions
diff --git a/lib/net.js b/lib/net.js index 54ddaa3b40..6c2bf56875 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 3f93b444f4..d2f7c5c212 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(); |