Skip to content
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

Request Timeouts dynamically calculated #55437

Open
1 task done
bradlis7 opened this issue Apr 30, 2024 · 3 comments
Open
1 task done

Request Timeouts dynamically calculated #55437

bradlis7 opened this issue Apr 30, 2024 · 3 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlesware

Comments

@bradlis7
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I am trying to set the timeout of my request dynamically, but it seems it must be a constant value.

Describe the solution you'd like

I would suggest that UseRequestTimeouts have a callback option with the request context to be evaluated and set the timeout value inside of this callback.

Additional context

I am using .net in Lambda, and I could use ILambdaContext.RemainingTime - buffer to determine when the timeout should happen, but I don't see how to do so with the current implementation.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Apr 30, 2024
@martincostello
Copy link
Member

Taking a quick look at the code, it doesn't look like it's possible to dynamically determine the timeout.

Maybe you could manually do something like the internals do by manually implementing and setting a IHttpRequestTimeoutFeature in a middleware like how the timeout middleware does itself?

async Task SetTimeoutAsync()
{
var originalToken = context.RequestAborted;
var (linkedCts, timeoutCts) = _cancellationTokenProvider.GetLinkedCancellationTokenSource(context, originalToken, timeSpan.Value);
try
{
var feature = new HttpRequestTimeoutFeature(timeoutCts);
context.Features.Set<IHttpRequestTimeoutFeature>(feature);
context.RequestAborted = linkedCts.Token;
await _next(context);
}

@bradlis7
Copy link
Author

Maybe you could manually do something like the internals do by manually implementing and setting a IHttpRequestTimeoutFeature in a middleware like how the timeout middleware does itself?

That's a good workaround, I'll do that for now.

@bradlis7
Copy link
Author

So many internal classes... in order to create a workaround, I have to copy a bunch of classes in. I guess I'll just use static timeouts for now.

@amcasey amcasey added area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlesware api-suggestion Early API idea and discussion, it is NOT ready for implementation and removed area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions labels May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlesware
Projects
None yet
Development

No branches or pull requests

3 participants