aspnetcore: System.IO.Pipelines.PipeReader.CopyToAsyncCore: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'start')
Description
Getting this exception in ASP.NET Core Runtime 5.0.11 Occurs occasionaly (quite small %). I checked and request seems to be not in cancelled state after it throws.
context?.HttpContext?.RequestAborted.IsCancellationRequested == false
Exception:
An unhandled exception was thrown by the application. System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'start')
at System.IO.Pipelines.PipeReader.CopyToAsyncCore[TStream](TStream destination, Func`4 writeAsync, CancellationToken cancellationToken)
at MP.Sdk.Edge.Web.Formatters.InputFormatterBase.ToBytesAsync(Stream stream) in /opt/teamcity/work/af8a0ab010c87174/src/Sdk/MP.Sdk.Edge.Web/Formatters/InputFormatterBase.cs:line 65
using (MemoryStream memoryStream = new MemoryStream())
{
using (stream)
{
// below throws
await stream.CopyToAsync(memoryStream);
}
return memoryStream.ToArray();
}
Reproduction Steps
Reproes in AWS with load balancer. No luck reproducing locally so far.
Expected behavior
shouldn’t throw exception
Actual behavior
Exception:
An unhandled exception was thrown by the application. System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'start')
at System.IO.Pipelines.PipeReader.CopyToAsyncCore[TStream](TStream destination, Func`4 writeAsync, CancellationToken cancellationToken)
at MP.Sdk.Edge.Web.Formatters.InputFormatterBase.ToBytesAsync(Stream stream) in /opt/teamcity/work/af8a0ab010c87174/src/Sdk/MP.Sdk.Edge.Web/Formatters/InputFormatterBase.cs:line 65
Regression?
was okay in netcoreapp2.1
Known Workarounds
none so far
Configuration
No response
Other information
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 18 (12 by maintainers)
Commits related to this issue
- Don't reuse Pipe buffer when body is read Fixes #38771 — committed to dotnet/aspnetcore by sebastienros 3 years ago
- Don't reuse Pipe buffer when body is read (#39071) Fixes #38771 — committed to dotnet/aspnetcore by sebastienros 3 years ago
- Don't reuse Pipe buffer when body is read Fixes #38771 — committed to dotnet/aspnetcore by sebastienros 3 years ago
- [release/6.0] Don't reuse Pipe buffer when body is read (#39376) * Don't reuse Pipe buffer when body is read Fixes #38771 * Fix spacing after merge * Fix spacing * Update Http1ContentLeng... — committed to dotnet/aspnetcore by github-actions[bot] 2 years ago
Reproduced!!!
!!! In .netcoreapp2.1 CopyToAsync returned empty byte array !!! In .net5.0 it throws exception
Some requests seem to have incorrect content-type. Reproes 100%. Data is json string.
that works:
curl -X POST "http://%ip%:3611/events" -d %data% --header "Content-Type: application/json; charset=utf-8"that doesn’t:
curl -X POST "http://%ip%:3611/events" -d %data%This might be an issue:
Content-Type',value='application/x-www-form-urlencodedtrying to create simple repro application, but porting to .net6.0 didn’t fix the issue