-
Notifications
You must be signed in to change notification settings - Fork 861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HttpForwarder failed to send body after update to version 1.1.0-rc.1.22152.1 from 1.0.1 #1657
Comments
The error indicates that YARP wasn't able to read any bytes from the request body. |
Hi MihaZupan No. Client not support http2. |
Were these requests that were previously succeeding? It might be that this is a case where the client disconnected before sending the request content. |
Hi MihaZupan It is reproduces always. It is also reproduceble from swagger or curl |
Can you provide a minimal runnable repro we could try? |
It is start reproducing with after merge of this PR |
If you call in any middleware before UseEndpoints app.Use((context, next) =>
{
context.Request.EnableBuffering();
....
return next(context);
}); Proxy will fail |
What's the rest of that middleware look like? Are you remembering to re-wind the request body after you read it? |
just this without extra lines app.Use((context, next) =>
{
context.Request.EnableBuffering();
return next(context);
}); I am planning to delete this middleware. |
Triage: @illay1994 can you please post a minimal repro (app) for us to check? The code snippets above are not fully helping :( |
Code exampe: test url: curl -X POST "https://localhost:5001/post" -H "accept: application/json" -d '{"a":123}' |
Thanks, I was able to reproduce this and track it back to dotnet/aspnetcore#41287. EnableBuffering is not compatible with the zero-byte read pattern, that's something we'll need to fix in aspnetcore. For Triage: recommend closing this as external. |
Related: #1665. Updated proposal: Skip zero-byte reads for 3.1 and 5.0, and patch AspNetCore 6 for any cases we find. |
Fixed by #1666 |
I am using yarp to proxy Grafana but I keep getting this error with some of the content. Googling the issue brought me here. .Net 7.0.3 and Yarp 2.0 So shouldn't be getting this issue. Any ideas? |
@karelz, this seems to still be an issue. I'm unable to read the request body. Using a similar approach as OP: app.UseSerilogRequestLogging(options =>
{
options.EnrichDiagnosticContext = (diagnosticContext, httpContext) =>
{
var body = GetRawBodyAsync(httpContext.Request).GetAwaiter().GetResult();
diagnosticContext.Set("RequestBody", body);
};
async Task<string> GetRawBodyAsync(HttpRequest request)
{
request.EnableBuffering();
using var reader = new StreamReader(request.Body, Encoding.UTF8);
var body = await reader.ReadToEndAsync();
request.Body.Position = 0;
return body;
}
});
app.MapReverseProxy(); // 👈 Filtered on certain endpoints & cannot log response body
app.Map("/{**catchall}", Results.BadRequest); // logs response body just fine Using <PackageReference Include="Serilog.AspNetCore" Version="7.0.0" />
<PackageReference Include="Yarp.ReverseProxy" Version="2.0.1" /> |
Comments on closed issues are not tracked, please open a new issue with the details for your scenario. |
Describe the bug
We have simple yarp proxy with configuration:
and
config file:
To Reproduce
in version 1.0.1 all working fine
after update to version 1.1.0-rc.1.22152.1 get error in log and return 400 HttpError code
logs:
Further technical details
The text was updated successfully, but these errors were encountered: