You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The JS stream in the NET 7.0 Blazor runtime blocks until either the stream has ended, or the C# buffer is full, preventing the developer from reading the responses as soon as they are ready. A workaround exists by limiting the read buffer size, but it prevents the usage of StreamReaders and still causes the StreamContent.ReadAsync() to not return with a zero.
The endlessly running await StreamContent.ReadAsync(...) also interferes with the other asynchronous operations, causing them to halt as well.
As in the original implementation, ReadableStreamDefaultReader.read() also blocks the execution if there is no data available, and currently there is no known API to check if there are bytes received or not.
Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.
Issue Details
The JS stream in the NET 7.0 Blazor runtime blocks until either the stream has ended, or the C# buffer is full, preventing the developer from reading the responses as soon as they are ready. A workaround exists by limiting the read buffer size, but it prevents the usage of StreamReaders and still causes the StreamContent.ReadAsync() to not return with a zero.
The endlessly running await StreamContent.ReadAsync(...) also interferes with the other asynchronous operations, causing them to halt as well.
As in the original implementation, ReadableStreamDefaultReader.read() also blocks the execution if there is no data available, and currently there is no known API to check if there are bytes received or not.
I also think we rather keep the loop over __reader.read(); in case that browser returned zero length chunk.
I worry it may happen when server sends zero sized chunk.
I think we need to block the promise/task until we receive at least one byte or until we get done.
The reason will be displayed to describe this comment to others. Learn more.
I think we need to block the promise/task until we receive at least one byte or until we get done.
Yes, unless zero bytes were requested (in which case you can either return immediately or wait for at least one byte to be available but not consume it), Stream.Read must not return 0 unless it's EOF, and Stream.ReadAsync must not complete the task with 0 unless it's EOF.
The reason will be displayed to describe this comment to others. Learn more.
Waiting until C# buffer is full is wrong in the current code, thanks for figuring it out @rabirland !
You're welcome. To remove the zero return, you gotta bridge the if (!res.body) check. After that, res__reader.read() will block until data is received.
The if (remaining_source === 0) need to re-run the chunk read, instead of returning and waiting for the C# side to call it again.
ghost
locked as resolved and limited conversation to collaborators
Feb 15, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The JS stream in the NET 7.0 Blazor runtime blocks until either the stream has ended, or the C# buffer is full, preventing the developer from reading the responses as soon as they are ready. A workaround exists by limiting the read buffer size, but it prevents the usage of
StreamReaders and still causes theStreamContent.ReadAsync()to not return with a zero.The endlessly running
await StreamContent.ReadAsync(...)also interferes with the other asynchronous operations, causing them to halt as well.Fix for: #79238
Known issues:
ReadableStreamDefaultReader.read()also blocks the execution if there is no data available, and currently there is no known API to check if there are bytes received or not.