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

Introduce AbpHttpClientBuilderOptions & Remove AbpHttpClientOptions.HttpClientActions #5304

Closed
hikalkan opened this issue Sep 5, 2020 · 4 comments

Comments

@hikalkan
Copy link
Member

hikalkan commented Sep 5, 2020

  • AbpHttpClientOptions.HttpClientActions was not properly designed and implemented. So, removed it in favor of AbpHttpClientBuilderOptions.ProxyClientBuildActions
  • Removed configureHttpClientBuilder option from AddHttpClientProxies method since it was inconsistent.

These are breaking changes but I am including it to version 3.2, because they had already problems and they have never been documented.

The proper way to configure HTTP Clients for dynamic c# proxies should be done in the PreConfigureServices method of your module, like the sample below:

public override void PreConfigureServices(ServiceConfigurationContext context)
{
    PreConfigure<AbpHttpClientBuilderOptions>(options =>
    {
        options.ProxyClientBuildActions.Add((remoteServiceName, clientBuilder) =>
        {
            clientBuilder.AddTransientHttpErrorPolicy(policyBuilder =>
                policyBuilder.WaitAndRetryAsync(
                    3,
                    i => TimeSpan.FromSeconds(Math.Pow(2, i))
                )
            );
        });
    });
}
  • This example configures all HTTP client proxies. remoteServiceName can be used to check and configure different service proxies differently.
  • clientBuilder (type: IHttpClientBuilder) is flexible to make any configuration, including Polly extension methods like done in the example.

This example is actually the default configuration (retry 3 times) for all client proxies. If you don't want it, just use options.ProxyClientBuildActions.Clear() in the PreConfigure.

@jee-a
Copy link

jee-a commented Feb 25, 2022

I am use ABP 3.0.3. It do not have AbpHttpClientOptions class. I have to what to do to increase timeout?

@maliming
Copy link
Member

Upgrade Your abp to the 3.2+.

@jee-a
Copy link

jee-a commented Feb 25, 2022

image
I configed. However when cross call via internal gateway among other services when stress test using Jmeter. The system is error: "2022-02-25 13:33:23.404 +07:00 [ERR] Connection id "0HMFO3HKQQKRH", Request id "0HMFO3HKQQKRH:00000002": An unhandled exception was thrown by the application.
System.Threading.Tasks.TaskCanceledException: The request was canceled due to the configured HttpClient.Timeout of 100 seconds elapsing.
---> System.TimeoutException: The operation was canceled.
---> System.Threading.Tasks.TaskCanceledException: The operation was canceled.
---> System.IO.IOException: Unable to read data from the transport connection: Operation canceled.
---> System.Net.Sockets.SocketException (125): Operation canceled
--- End of inner exception stack trace ---
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.GetResult(Int16 token)
at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at Microsoft.Extensions.Http.Logging.LoggingHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at Polly.Retry.AsyncRetryEngine.ImplementationAsync[TResult](Func3 action, Context context, CancellationToken cancellationToken, ExceptionPredicates shouldRetryExceptionPredicates, ResultPredicates1 shouldRetryResultPredicates, Func5 onRetryAsync, Int32 permittedRetryCount, IEnumerable1 sleepDurationsEnumerable, Func4 sleepDurationProvider, Boolean continueOnCapturedContext) at Polly.AsyncPolicy1.ExecuteAsync(Func`3 action, Context context, CancellationToken cancellationToken, Boolean continueOnCapturedContext)
at Microsoft.Extensions.Http.PolicyHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at Microsoft.Extensions.Http.Logging.LoggingScopeHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.SendAsyncCore(HttpRequestMessage request, HttpCompletionOption completionOption, Boolean async, Boolean emitTelemetryStartStop, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
--- End of inner exception stack trace ---"

@jee-a
Copy link

jee-a commented Feb 25, 2022

Upgrade Your abp to the 3.2+.

I configed timeout. However it is failed. The request was canceled due to the configured HttpClient.Timeout of 100 seconds elapsing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants