Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dfbbfbb

Browse filesBrowse files
lpincaBridgeAR
authored andcommitted
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: #27996 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent e5c2675 commit dfbbfbb
Copy full SHA for dfbbfbb

File tree

Expand file treeCollapse file tree

2 files changed

+10
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+10
-2
lines changed
Open diff view settings
Collapse file

‎lib/net.js‎

Copy file name to clipboardExpand all lines: lib/net.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ function writeAfterFIN(chunk, encoding, cb) {
410410
if (typeof cb === 'function') {
411411
defaultTriggerAsyncIdScope(this[async_id_symbol], process.nextTick, cb, er);
412412
}
413+
414+
return false;
413415
}
414416

415417
Socket.prototype.setTimeout = setStreamTimeout;
Collapse file

‎test/parallel/test-net-write-after-end-nt.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-net-write-after-end-nt.js
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const common = require('../common');
44
const assert = require('assert');
55
const net = require('net');
66

7-
const { mustCall } = common;
7+
const { expectsError, mustCall } = common;
88

99
// This test ensures those errors caused by calling `net.Socket.write()`
1010
// after sockets ending will be emitted in the next tick.
@@ -18,7 +18,13 @@ const server = net.createServer(mustCall((socket) => {
1818
server.close();
1919
}));
2020
client.on('end', mustCall(() => {
21-
client.write('hello', mustCall());
21+
const ret = client.write('hello', expectsError({
22+
code: 'EPIPE',
23+
message: 'This socket has been ended by the other party',
24+
type: Error
25+
}));
26+
27+
assert.strictEqual(ret, false);
2228
assert(!hasError, 'The error should be emitted in the next tick.');
2329
}));
2430
client.end();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.