-
Notifications
You must be signed in to change notification settings - Fork 161
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
Stream read hangs when stream is closed during a BYOB read #1321
Comments
With the current For example, consider the following stream: const stream = new ReadableStream({
type: 'bytes',
async pull(controller) {
const { byobRequest } = controller;
const { buffer, byteOffset, byteLength } = byobRequest;
const newBuffer = buffer.transfer();
const bytesWritten = await fillBuffer(buffer, byteOffset, byteLength);
if (bytesWritten === 0) {
controller.close();
byobRequest.respondWithNewView(new Uint8Array(newBuffer, byteOffset, 0));
} else {
byobRequest.respondWithNewView(new Uint8Array(newBuffer, byteOffset, byteLength));
}
}
}); Here, the stream is transferring the BYOB buffer before filling it. It can do this with an explicit The I agree that it's annoying that you have to call
|
Edited 8/16 to fix (at least one) misunderstanding on my part I certainly have not considered all the potential scenarios, but I also find it odd that you can even
|
I was also thinking that the current design seems susceptible to race conditions unless the implementer ensures there is either never an |
@MattiasBuelens Any feedback the last two comments? |
When constructing a ReadableStream and then reading it with a ReadableStreamBYOBReader (for example to control the size of reads), if the stream is closed during the read request without enqueued data, the read request hangs. This is problematic when the stream is used from a library by unknown callers. The solution is to not ignore BYOB in the stream implementation and call
close()
followed bycontroller.byobRequest.respond(0)
, but that is unexpected when the readable stream otherwise ignores BYOB. Why isn't callingclose()
alone sufficient?More detail, code examples, and the workaround can be found in this Stack Overflow question: https://stackoverflow.com/questions/78804588/why-does-read-not-return-in-byob-mode-when-stream-is-closed
The text was updated successfully, but these errors were encountered: