Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
Similar to #41287 and #41305, TestHost also doesn't expect/support 0-byte reads on the body.
aspnetcore/src/Hosting/TestHost/src/ResponseBodyReaderStream.cs
Lines 118 to 121 in 3888fda
Expected Behavior
The 0-byte read should not throw and subsequent reads should return available data.
Steps To Reproduce
See yarp.zip (repro attached in the original Yarp issue)
Exceptions (if any)
Yarp.ReverseProxy.Forwarder.HttpForwarder[48]
ResponseBodyDestination: The destination reported an error when copying the response body.
System.ArgumentOutOfRangeException: (Parameter 'count')
Actual value was 0.
at Microsoft.AspNetCore.TestHost.ResponseBodyReaderStream.VerifyBuffer(Byte[] buffer, Int32 offset, Int32 count)
at Microsoft.AspNetCore.TestHost.ResponseBodyReaderStream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
at Yarp.ReverseProxy.Forwarder.StreamCopier.CopyAsync(Stream input, Stream output, Int64 promisedContentLength, StreamCopierTelemetry telemetry, ActivityCancellationTokenSource activityToken, CancellationToken cancellation)
.NET Version
6.0.5
Anything else?
Discovered by a user writing unit tests that include Yarp dotnet/yarp#1720
cc: @Tratcher @adityamandaleeka
There kind of failures can be caught by StreamConformanceTests we run in runtime.
For example, here are 0-byte read tests for HttpClient response streams.
Are there any plans to include such tests in AspNetCore (for this specific kind of issue, it may be easier to just manually audit all stream implementations)?