[release/6.0] Support zero-byte reads on raw response streams in SocketsHttpHandler #72804
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.
Backporting a minimal change to support zero-byte reads for 1.1 WebSockets (contributes to #61475).
Product change is 25029a7 from #61913. It skips changing zero-byte reads for non-WebSockets HTTP (1.x, 2, 3).
Customer Impact
Zero-byte reads are a way of deferring memory allocations while waiting for data to become available.
Their use can significantly reduce memory usage in networking scenarios where idle connections are common.
WebSocket connections represent a scenario that benefits greatly from this.
Zero-byte reads also allow us to avoid pinning large buffers for extended periods of time, avoiding heap fragmentation.
An internal partner facing memory issues due to fragmentation saw a 10x reduction in memory usage with this patch.
Testing
A targeted test case has been added and the patch was validated by an internal party in production.
Risk
Low.
The change is limited in scope to only HTTP/1.1 WebSocket connections.
It has been tested in 7.0 previews for more than half a year with no reported issues.
In order for the user to observe any changes after this patch, they must be explicitly issuing zero-byte reads, which has been uncommon so far (and always a no-op with HttpClient before 7.0).