-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Description
📗 API Reference Docs Problem
- Version: v15.12.0
- Platform: Darwin Shauns-MacBook-Pro.local 20.3.0 Darwin Kernel Version 20.3.0: Thu Jan 21 00:07:06 PST 2021; root:xnu-7195.81.3~1/RELEASE_X86_64 x86_64
- Subsystem: stream
Location
Section of the site where the content exists
Affected URL(s):
Description
Concise explanation of the problem
The documentation for implementing a readable stream indicates that the _read
function should continue reading from the resource until stream.push
returns false. When I implemented my stream this way, I saw the opposite behavior. stream._read
was called every time it ran stream.push(...)
, resulting in hundreds of concurrent read operations.
More Detail
When readable._read() is called, if data is available from the resource, the implementation should begin pushing that data into the read queue using the this.push(dataChunk) method. _read() should continue reading from the resource and pushing data until readable.push() returns false. Only when _read() is called again after it has stopped should it resume pushing additional data onto the queue.
I quickly noticed a memory leak in my application, because readable._read
was getting called every time I ran readable.push(...)
(when the buffer was below highWaterMark
), which meant there may be hundreds of concurrent read operations on the same resource. I would like to reword this section to eliminate this ambiguity and clarify that the _read
function may be called multiple times before reaching the highWaterMark
.
I would be interested in contributing to this, but I would want some clarification first. Why would we need to listen to the result of stream.push(...)
if _read
doesn't get called when the buffer is full? For edge cases where data is pushed outside the _read
function, stream.push(...)
's return value is documented here, but it doesn't seem to have a use from within _read
.
- I would like to work on this issue and
submit a pull request.