stream: avoid duplicated endReadableNT scheduling · nodejs/node@c42fbcc · GitHub
Skip to content

Commit c42fbcc

Browse files
mcollinaaduh95
authored andcommitted
stream: avoid duplicated endReadableNT scheduling
Calling read() on an ended stream multiple times before the microtask queue drains scheduled one endReadableNT tick per call, as the only guard was endEmitted, which is set inside the tick itself. A hello-world HTTP server was scheduling it four times per request while dumping the unread request body. Introduce a kEndScheduled flag armed when the tick is scheduled and cleared when it runs. Clearing it unconditionally matters for reused sockets: undestroy() resets endEmitted through the state descriptors but cannot reach this flag, and a stale value would block the 'end' event after a net.Socket reconnect. Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: #65310 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it>
1 parent acaf986 commit c42fbcc

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

lib/internal/streams/readable.js

Lines changed: 9 additions & 2 deletions

0 commit comments

Comments
 (0)