Skip to content

Commit

Permalink
Dispose ClientClusterManifestProvider when OutsideRuntimeClient i…
Browse files Browse the repository at this point in the history
…s stopping (#9211)

* Ensure ClientClusterManifestProvider's DisposeAsync is called as part of OutsideRuntimeClient

---------

Co-authored-by: Ledjon Behluli <Ledjon@notiphy.io>
Co-authored-by: Reuben Bond <203839+ReubenBond@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 2, 2024
1 parent 85bfbde commit c78ee8c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
21 changes: 21 additions & 0 deletions src/Orleans.Core/Manifest/ClientClusterManifestProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,27 @@ public Task StartAsync()
return _initialized.Task;
}

public async Task StopAsync(CancellationToken cancellationToken)
{
try
{
_cancellation.Cancel();

if (_runTask is { IsCompleted: false } _task)
{
await _task.WaitAsync(cancellationToken);
}
}
catch (OperationCanceledException)
{
_logger.LogInformation("Graceful shutdown of cluster manifest provider was canceled.");
}
catch (Exception exception)
{
_logger.LogError(exception, "Error stopping cluster manifest provider.");
}
}

private async Task RunAsync()
{
try
Expand Down
11 changes: 9 additions & 2 deletions src/Orleans.Core/Runtime/OutsideRuntimeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

namespace Orleans
{

internal class OutsideRuntimeClient : IRuntimeClient, IDisposable, IClusterConnectionStatusListener
{
internal static bool TestOnlyThrowExceptionDuringInit { get; set; }
Expand All @@ -37,6 +36,7 @@ internal class OutsideRuntimeClient : IRuntimeClient, IDisposable, IClusterConne

public IInternalGrainFactory InternalGrainFactory { get; private set; }

private ClientClusterManifestProvider _manifestProvider;
private MessageFactory messageFactory;
private readonly LocalClientDetails _localClientDetails;
private readonly ILoggerFactory loggerFactory;
Expand Down Expand Up @@ -98,6 +98,7 @@ internal void ConsumeServices()
try
{
_statusObservers = this.ServiceProvider.GetServices<IClusterConnectionStatusObserver>().ToArray();
_manifestProvider = ServiceProvider.GetRequiredService<ClientClusterManifestProvider>();

this.InternalGrainFactory = this.ServiceProvider.GetRequiredService<IInternalGrainFactory>();
this.messageFactory = this.ServiceProvider.GetService<MessageFactory>();
Expand Down Expand Up @@ -148,6 +149,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
public async Task StopAsync(CancellationToken cancellationToken)
{
this.callbackTimer.Dispose();

if (this.callbackTimerTask is { } task)
{
await task.WaitAsync(cancellationToken);
Expand All @@ -158,6 +160,11 @@ public async Task StopAsync(CancellationToken cancellationToken)
await messageCenter.StopAsync(cancellationToken);
}

if (_manifestProvider is { } provider)
{
await provider.StopAsync(cancellationToken);
}

ConstructorReset();
}

Expand All @@ -184,7 +191,7 @@ await ExecuteWithRetries(
this.InternalGrainFactory.CreateObjectReference<IClientGatewayObserver>(this.gatewayObserver);

await ExecuteWithRetries(
async () => await this.ServiceProvider.GetRequiredService<ClientClusterManifestProvider>().StartAsync(),
_manifestProvider.StartAsync,
retryFilter,
cancellationToken);

Expand Down

0 comments on commit c78ee8c

Please sign in to comment.