Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadableStreamFrom pull until cannot on empty enqueu #4002

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

KhafraDev
Copy link
Member

refs: nodejs/node#56474

ReadableByteStreamController.enqueue handles empty typed arrays differently than the normal ReadableStreamController: it throws an error when receiving one. To combat this, we didn't enqueue anything and did nothing if the buffer was empty. For whatever reason, this caused the promise to never resolve (I didn't dig into the spec long enough to figure out why, sorry). The fix is to simply continue pulling until we respond to the pull in some manner.

I am not a webstreams expert please review with caution.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This controller.desiredSize > 0 is what makes backpressure possible and what makes sure we do not have a memory leak. It's critical.

@KhafraDev
Copy link
Member Author

@KhafraDev
Copy link
Member Author

This method, also defined by the developer, will be called repeatedly when the stream's internal queue of chunks is not full, up
until it reaches its high water mark. If pull() returns a promise, then it won't be called again until that promise fulfills

https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/ReadableStream

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants