Skip to content

Commit

Permalink
CR
Browse files Browse the repository at this point in the history
  • Loading branch information
deniaa committed Aug 5, 2024
1 parent fccee1e commit 45f9f90
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Vostok.ClusterClient.Core/Misc/ClusterClientConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions Vostok.ClusterClient.Core/Misc/TimeSpanExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task<Response> 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);
Expand Down

0 comments on commit 45f9f90

Please sign in to comment.