Skip to content

Commit

Permalink
Avoid constant try/catch on a non-existing gateway for external clust…
Browse files Browse the repository at this point in the history
…er client (#8792)

* Avoid constant try/catch on a non-existing gateway for external cluster client connection

* Put a delay so that calling GetLiveGateway doesn't happen so frequently

---------

Co-authored-by: Ledjon Behluli <Ledjon@notiphy.io>
  • Loading branch information
ledjon-behluli and Ledjon Behluli authored Jan 9, 2024
1 parent cab108e commit 876d4ec
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Orleans.Core/Manifest/ClientClusterManifestProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ private async Task RunAsync()
if (gateway is null || !_gatewayManager.IsGatewayAvailable(gateway))
{
gateway = _gatewayManager.GetLiveGateway();
if (gateway is null)
{
await Task.Delay(StandardExtensions.Min(_typeManagementOptions.TypeMapRefreshInterval, TimeSpan.FromMilliseconds(500)));
continue;
}

provider = grainFactory.GetGrain<IClusterManifestSystemTarget>(SystemTargetGrainId.Create(Constants.ManifestProviderType, gateway).GrainId);

// Accept any cluster manifest version from the new gateway.
Expand Down
5 changes: 4 additions & 1 deletion src/Orleans.Core/Messaging/GatewayManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ public override string ToString()
/// is in the same order every time.
/// </summary>
/// <returns></returns>
public SiloAddress GetLiveGateway()
#nullable enable
public SiloAddress? GetLiveGateway()
#nullable disable
{
List<SiloAddress> live = GetLiveGateways();
int count = live.Count;
Expand All @@ -168,6 +170,7 @@ public SiloAddress GetLiveGateway()
// If we drop through, then all of the known gateways are presumed dead
return null;
}


public List<SiloAddress> GetLiveGateways()
{
Expand Down
1 change: 1 addition & 0 deletions test/TesterInternal/GatewaySelectionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected async Task Test_GatewaySelection(IGatewayListProvider listProvider)
for (int i = 0; i < 2300; i++)
{
var ip = gatewayManager.GetLiveGateway();
Assert.NotNull(ip);
var addr = ip.Endpoint.Address;
Assert.Equal(IPAddress.Loopback, addr); // "Incorrect IP address returned for gateway"
Assert.True((0 < ip.Endpoint.Port) && (ip.Endpoint.Port < 5), "Incorrect IP port returned for gateway");
Expand Down

0 comments on commit 876d4ec

Please sign in to comment.