Skip to content

TestHost response body does not support 0-byte reads #41692

Closed
@MihaZupan

Description

@MihaZupan

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.

if (count <= 0 || count > buffer.Length - offset)
{
throw new ArgumentOutOfRangeException(nameof(count), count, string.Empty);
}

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)?

Metadata

Metadata

Assignees

Labels

area-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsbugThis issue describes a behavior which is not expected - a bug.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions