-
Notifications
You must be signed in to change notification settings - Fork 833
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
IHttpForwarder and cancellation #1542
Comments
I agree with this from the perspective of runtime APIs, but this doesn't seem to be the pattern AspNet follows to my knowledge:
app.MapGet("/delay1", async (CancellationToken ct) => // blows up at runtime
{
while (true)
{
Console.WriteLine(ct.IsCancellationRequested);
await Task.Delay(1000);
}
});
app.MapGet("/delay2", async (HttpContext context) =>
{
while (true)
{
Console.WriteLine(context.RequestAborted.IsCancellationRequested);
await Task.Delay(1000);
}
}); With YARP being in the middle between runtime and AspNet, do we believe YARP users are more error-prone to this than those of other web apps? |
The main difference I see is that Middleware isn't invoked by users, it's invoked by the runtime that doesn't need to customize parameters. IHttpForwarder is an API invoked by the user more like HttpClient that does take a CT. |
You can and also into MVC controller actions. |
Oh was that added in 7? |
6.0 supports cancellation tokens but MVC always supported it. |
IHttpForwarder.SendAsync does not directly accept a CancellationToken to abort it. It supports canceling if the ForwarderRequestConfig.ActivityTimeout expires, or if HttpContext.RequestAborted triggers (client disconnect).
reverse-proxy/src/ReverseProxy/Forwarder/IHttpForwarder.cs
Lines 25 to 26 in 79c88ce
A customer that wanted to add their own cancellation condition did so by replacing HttpContext.RequestAborted. However, this caused an issue where they were leaking resources because they were no longer responding to the original RequestAborted token. The fix was to chain the two tokens.
Feedback: Having a CancellationToken parameter on IHttpForwarder.SendAsync would make this less error prone.
The text was updated successfully, but these errors were encountered: