dotnet-sdk icon indicating copy to clipboard operation
dotnet-sdk copied to clipboard

How to set the DaprClient invoke timeout

Open johnseed opened this issue 2 years ago • 7 comments

How to set the DaprClient invoke timeout

I have an API that takes 2 minutes to complete, but the DaprClient invoke will time out after 100 seconds.

System.Threading.Tasks.TaskCanceledException: 'The request was canceled due to the configured HttpClient.Timeout of 100 seconds elapsing.'
   at System.Net.Http.HttpClient.HandleFailure(Exception e, Boolean telemetryStarted, HttpResponseMessage response, CancellationTokenSource cts, CancellationToken cancellationToken, CancellationTokenSource pendingRequestsCts)
   at System.Net.Http.HttpClient.<<SendAsync>g__Core|83_0>d.MoveNext()
   at Dapr.Client.DaprClientGrpc.<InvokeMethodWithResponseAsync>d__24.MoveNext()
   at Dapr.Client.DaprClientGrpc.<InvokeMethodAsync>d__26`1.MoveNext()
   at Program.<<Main>$>d__0.MoveNext() in C:\Users\John\source\repos\DaprGround\Invoke.Client\Program.cs:line 17

johnseed avatar Jan 09 '23 10:01 johnseed

Add some parameters here? https://github.com/dapr/dotnet-sdk/blob/ab5403ed015d7ba46099cf829186e2ea7d6264a5/src/Dapr.Client/DaprClientBuilder.cs#L166

johnseed avatar Jan 09 '23 10:01 johnseed

@johnseed - Thanks for bringing this up. We do need a way to expose this, which would probably be best done by exposing the actual factory/creation method. I'll discuss it with some of the other active people in the repo.

In the meantime, since you're using a direct http invoke, you can also do this with a raw HttpClient. Then you'd have full control over it, but you'd need to construct the endpoint yourself.

halspang avatar Feb 01 '23 19:02 halspang

@halspang any updates on this one? We have a requirement to let user download large attachments that could take more than 5 minutes to generate on server. But it's always timeout after 100 seconds.

ronnie-chew avatar Mar 10 '23 18:03 ronnie-chew

I'm facing the same shit, wtf with .net 7

MishaVernik avatar Mar 19 '23 15:03 MishaVernik

In DaprClientBuilder.cs `

internal DaprClientBuilder UseHttpClientFactory(Func<HttpClient> factory)
{
  this.HttpClientFactory = factory;
  return this;
}

` Why not use public? We cannot customize the timeout time

huxingye avatar Apr 07 '23 07:04 huxingye

I'm looking also into this to use the HttpClientFactory to inject middleware like for example an exception logger middleware

for example: A factory functions like this

Func<HttpClient> factory = () =>
{
    var httpClientHandler = new HttpClientHandler();
    var loggingMiddleware = new LogInternalServerErrorMiddleware(httpClientHandler);

    return new HttpClient(loggingMiddleware);
};

And pass it to UseHttpClientFactory(Func<HttpClient> factory)

BartNetJS avatar Apr 14 '23 15:04 BartNetJS

how about this? https://docs.dapr.io/operations/resiliency/resiliency-overview/

fissssssh avatar Sep 25 '23 06:09 fissssssh

Closed with #1252

philliphoff avatar Jul 23 '24 17:07 philliphoff