alefranz / HeaderPropagation

ASP.NET Core middleware to propagate HTTP headers from the incoming request to the outgoing HTTP Client requests. This is a backport to ASP.NET Core 2.1 (and 2.2) of the ASP.NET Core HeaderPropagation middleware I had recently contributed to the ASP.NET Core project.
Apache License 2.0
31 stars 1 forks source link

Headers mangled without previous async middleware #7

Closed orthoplex64 closed 4 years ago

orthoplex64 commented 5 years ago

When using app.UseHeaderPropagation(); as the first middleware in the pipeline and sending many simultaneous requests, I've observed incorrect headers being propagated sometimes.
When inserting any async middleware before header propagation (e.g. app.Use(async (context, next) => await next.Invoke());), all propagated headers are correct.

alefranz commented 5 years ago

Hi Christopher, thanks for reaching out. Which version of AspNetCore are you using? Do you have a repro to share? Thanks

orthoplex64 commented 5 years ago

I'm using ASP.NET Core 2.2. Sorry, I don't have a repository, but I'll put one together and get back to you.

alefranz commented 5 years ago

That would really help.

The middleware get the headers from the HttpContext and put then in a AsyncLocal so I can't think of a reason when this could fail.

Are you consuming an HttpClient configured with the header propagation also from outside of the request pipeline (e.g. from a IHostedService)?

orthoplex64 commented 5 years ago

Here's a repository with a demo project: https://github.com/orthoplex64/dotnet-demos The HttpClient is being consumed within the request pipeline, in a controller action

orthoplex64 commented 5 years ago

I submitted this issue to the ASP.NET Core project as well, and it was identified with a known problem with Kestrel: https://github.com/aspnet/AspNetCore/issues/15384

alefranz commented 4 years ago

Thanks! this really helps to understand the problem! I'll work on a solution

alefranz commented 4 years ago

I've released 3.0.2 which address the issue. Thank you for your help!