From 45f9f901f8134cc41cc2bd30f1bbeef991f342e1 Mon Sep 17 00:00:00 2001 From: deniaa Date: Mon, 5 Aug 2024 23:47:08 +0500 Subject: [PATCH] CR --- Vostok.ClusterClient.Core/Misc/ClusterClientConstants.cs | 4 ++-- Vostok.ClusterClient.Core/Misc/TimeSpanExtensions.cs | 4 ++-- .../Strategies/ForkingRequestStrategy.cs | 2 +- .../Strategies/ParallelRequestStrategy.cs | 2 +- .../Strategies/SequentialRequestStrategy.cs | 2 +- .../Transport/ConnectionAttemptsTransport.cs | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Vostok.ClusterClient.Core/Misc/ClusterClientConstants.cs b/Vostok.ClusterClient.Core/Misc/ClusterClientConstants.cs index b46dc33..271f2fe 100644 --- a/Vostok.ClusterClient.Core/Misc/ClusterClientConstants.cs +++ b/Vostok.ClusterClient.Core/Misc/ClusterClientConstants.cs @@ -2,10 +2,10 @@ namespace Vostok.Clusterclient.Core.Misc; -public static class ClusterClientConstants +internal static class ClusterClientConstants { //(deniaa): We can't use "null" as connection time budget because of a bug in Net6. - // Also we can't use TimeBudget.Remaining as connection time budget on last attempt in strategies + // Also we can't use TimeBudget.Remaining as connection time budget for the last attempt in strategies // because of HttpMessageHandler cache in Vostok.Clusterclient.Transport.Sockets.SocketsHandlerProvider. // Connection timeout is a key in this cache and we don't want to create a new HttpMessageHandler for each request. // So we want to have only one constant "Infinite" for the whole ClusterClient. diff --git a/Vostok.ClusterClient.Core/Misc/TimeSpanExtensions.cs b/Vostok.ClusterClient.Core/Misc/TimeSpanExtensions.cs index c9e839a..23dc317 100644 --- a/Vostok.ClusterClient.Core/Misc/TimeSpanExtensions.cs +++ b/Vostok.ClusterClient.Core/Misc/TimeSpanExtensions.cs @@ -3,9 +3,9 @@ namespace Vostok.Clusterclient.Core.Misc; -public static class TimeSpanExtensions +internal static class TimeSpanExtensions { - public static TimeSpan? Max(TimeSpan lastAttemptConnectionTimeBudget, TimeSpan? connectionTimeoutFromParameters) + public static TimeSpan? SelectConnectionTimeoutForLastAttempt(TimeSpan lastAttemptConnectionTimeBudget, TimeSpan? connectionTimeoutFromParameters) { return connectionTimeoutFromParameters == null ? lastAttemptConnectionTimeBudget diff --git a/Vostok.ClusterClient.Core/Strategies/ForkingRequestStrategy.cs b/Vostok.ClusterClient.Core/Strategies/ForkingRequestStrategy.cs index 738d03a..6fe0888 100644 --- a/Vostok.ClusterClient.Core/Strategies/ForkingRequestStrategy.cs +++ b/Vostok.ClusterClient.Core/Strategies/ForkingRequestStrategy.cs @@ -85,7 +85,7 @@ public async Task SendAsync(Request request, RequestParameters parameters, IRequ } var connectionAttemptTimeout = i == replicasCount - 1 - ? TimeSpanExtensions.Max(ClusterClientConstants.LastAttemptConnectionTimeBudget, parameters.ConnectionTimeout) + ? TimeSpanExtensions.SelectConnectionTimeoutForLastAttempt(ClusterClientConstants.LastAttemptConnectionTimeBudget, parameters.ConnectionTimeout) : parameters.ConnectionTimeout; LaunchRequest(currentTasks, request, budget, sender, replicasEnumerator, connectionAttemptTimeout, linkedCancellationToken); diff --git a/Vostok.ClusterClient.Core/Strategies/ParallelRequestStrategy.cs b/Vostok.ClusterClient.Core/Strategies/ParallelRequestStrategy.cs index cc7e4a1..4bcb657 100644 --- a/Vostok.ClusterClient.Core/Strategies/ParallelRequestStrategy.cs +++ b/Vostok.ClusterClient.Core/Strategies/ParallelRequestStrategy.cs @@ -60,7 +60,7 @@ public async Task SendAsync(Request request, RequestParameters parameters, IRequ if (!replicasEnumerator.MoveNext()) throw new InvalidOperationException("Replicas enumerator ended prematurely. This is definitely a bug in code."); - var connectionTimeout = TimeSpanExtensions.Max(ClusterClientConstants.LastAttemptConnectionTimeBudget, parameters.ConnectionTimeout); + var connectionTimeout = TimeSpanExtensions.SelectConnectionTimeoutForLastAttempt(ClusterClientConstants.LastAttemptConnectionTimeBudget, parameters.ConnectionTimeout); currentTasks.Add(sender.SendToReplicaAsync(replicasEnumerator.Current, request, connectionTimeout, budget.Remaining, linkedCancellationToken)); } diff --git a/Vostok.ClusterClient.Core/Strategies/SequentialRequestStrategy.cs b/Vostok.ClusterClient.Core/Strategies/SequentialRequestStrategy.cs index de5e686..e834b1b 100644 --- a/Vostok.ClusterClient.Core/Strategies/SequentialRequestStrategy.cs +++ b/Vostok.ClusterClient.Core/Strategies/SequentialRequestStrategy.cs @@ -54,7 +54,7 @@ public async Task SendAsync(Request request, RequestParameters parameters, IRequ var timeout = TimeSpanArithmetics.Min(timeoutsProvider.GetTimeout(request, budget, currentReplicaIndex++, replicasCount), budget.Remaining); var connectionAttemptTimeout = currentReplicaIndex == replicasCount - ? TimeSpanExtensions.Max(ClusterClientConstants.LastAttemptConnectionTimeBudget, parameters.ConnectionTimeout) + ? TimeSpanExtensions.SelectConnectionTimeoutForLastAttempt(ClusterClientConstants.LastAttemptConnectionTimeBudget, parameters.ConnectionTimeout) : parameters.ConnectionTimeout; var result = await sender.SendToReplicaAsync(replica, request, connectionAttemptTimeout, timeout, cancellationToken).ConfigureAwait(false); diff --git a/Vostok.ClusterClient.Core/Transport/ConnectionAttemptsTransport.cs b/Vostok.ClusterClient.Core/Transport/ConnectionAttemptsTransport.cs index 705a652..15130ff 100644 --- a/Vostok.ClusterClient.Core/Transport/ConnectionAttemptsTransport.cs +++ b/Vostok.ClusterClient.Core/Transport/ConnectionAttemptsTransport.cs @@ -34,7 +34,7 @@ public async Task SendAsync(Request request, TimeSpan? connectionTimeo for (var attempt = 1; attempt <= connectionAttempts; ++attempt) { var connectionAttemptTimeout = connectionTimeout == null || timeBudget.Remaining < connectionTimeout - ? TimeSpanExtensions.Max(ClusterClientConstants.LastAttemptConnectionTimeBudget, connectionTimeout) + ? TimeSpanExtensions.SelectConnectionTimeoutForLastAttempt(ClusterClientConstants.LastAttemptConnectionTimeBudget, connectionTimeout) : connectionTimeout.Value; var response = await transport.SendAsync(request, connectionAttemptTimeout, timeBudget.Remaining, cancellationToken).ConfigureAwait(false);