Skip to content

Commit

Permalink
stream: investigate memory overconsumption by Stream.Readable.toWeb
Browse files Browse the repository at this point in the history
  • Loading branch information
lilsweetcaligula committed Feb 14, 2023
1 parent 6bbc2fb commit 1f0e249
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/internal/webstreams/readablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,14 @@ function readableStreamError(stream, error) {
}
}

function readableStreamHasReader(stream) {
const {
reader,
} = stream[kState];

return reader != null;
}

function readableStreamHasDefaultReader(stream) {
const {
reader,
Expand Down Expand Up @@ -2230,6 +2238,10 @@ function readableStreamDefaultControllerShouldCallPull(controller) {
!controller[kState].started)
return false;

if (!readableStreamHasReader(stream)) {
return false;
}

if (isReadableStreamLocked(stream) &&
readableStreamGetNumReadRequests(stream)) {
return true;
Expand Down Expand Up @@ -2466,6 +2478,11 @@ function readableByteStreamControllerShouldCallPull(controller) {
!controller[kState].started) {
return false;
}

if (!readableStreamHasReader(stream)) {
return false;
}

if (readableStreamHasDefaultReader(stream) &&
readableStreamGetNumReadRequests(stream) > 0) {
return true;
Expand Down

0 comments on commit 1f0e249

Please sign in to comment.