mirror of
https://github.com/nodejs/node.git
synced 2026-11-30 11:55:44 -05:00
http: avoid stream listeners on idle agent sockets
Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: https://github.com/nodejs/node/pull/64004 Fixes: https://github.com/nodejs/node/issues/63989 Reviewed-By: René <contact.9a5d6388@renegade334.me.uk> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com>
This commit is contained in:
1 parent
41d2ee13be
commit
eaa292549e
3 files changed
+67
-13
No files matched your search
@@ -8,8 +8,8 @@
|
||||
// writes a full HTTP response during this window, it is consumed as the
|
||||
// response for the *next* request — poisoning the response queue.
|
||||
//
|
||||
// The fix attaches a data guard listener + resume() on idle sockets so
|
||||
// that unsolicited data causes the socket to be destroyed.
|
||||
// The fix installs a read guard on idle sockets so that unsolicited data
|
||||
// causes the socket to be destroyed without adding public stream listeners.
|
||||
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
@@ -48,8 +48,9 @@ server.listen(0, common.mustCall(() => {
|
||||
assert.strictEqual(agent.freeSockets[name]?.length, 1);
|
||||
const freeSocket = agent.freeSockets[name][0];
|
||||
assert.strictEqual(freeSocket.parser, null);
|
||||
// With the fix, a data guard listener is attached
|
||||
assert.strictEqual(freeSocket.listenerCount('data'), 1);
|
||||
// With the fix, no public stream listeners are added.
|
||||
assert.strictEqual(freeSocket.listenerCount('data'), 0);
|
||||
assert.strictEqual(freeSocket.listenerCount('readable'), 0);
|
||||
|
||||
// Step 2: Server injects a poisoned response while socket is idle
|
||||
serverSocket.write(
|
||||
|
||||
@@ -149,8 +149,9 @@ server.listen(0, common.mustCall(() => {
|
||||
function checkListeners(socket) {
|
||||
const callback = common.mustCall(() => {
|
||||
if (!socket.destroyed) {
|
||||
// Sockets have freeSocketDataGuard while in the free pool.
|
||||
assert.strictEqual(socket.listenerCount('data'), 1);
|
||||
// Sockets have no public stream guard listeners while in the free pool.
|
||||
assert.strictEqual(socket.listenerCount('readable'), 0);
|
||||
assert.strictEqual(socket.listenerCount('data'), 0);
|
||||
assert.strictEqual(socket.listenerCount('drain'), 0);
|
||||
// Sockets have freeSocketErrorListener.
|
||||
assert.strictEqual(socket.listenerCount('error'), 1);
|
||||
|
||||
Reference in new issue
Block a user