Skip to content

Commit

Permalink
Tweak shutdown completion signalling (#6685) (#6696)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReubenBond authored Aug 18, 2020
1 parent 74b71a1 commit b56da8f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Orleans.Runtime/Hosting/DefaultSiloServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ internal static void AddDefaultServices(IApplicationPartManager applicationPartM

// Register system services.
services.TryAddSingleton<ILocalSiloDetails, LocalSiloDetails>();
services.TryAddSingleton<ISiloHost, SiloWrapper>();
services.TryAddSingleton<ISiloHost, SiloHost>();
services.TryAddTransient<ILifecycleSubject, LifecycleSubject>();
services.TryAddSingleton<SiloLifecycleSubject>();
services.TryAddFromExisting<ISiloLifecycleSubject, SiloLifecycleSubject>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

namespace Orleans.Hosting
{
internal class SiloWrapper : ISiloHost
internal class SiloHost : ISiloHost
{
private readonly Silo silo;
private readonly SiloApplicationLifetime applicationLifetime;
private bool isDisposing;

public SiloWrapper(Silo silo, IServiceProvider services)
public SiloHost(Silo silo, IServiceProvider services)
{
this.Services = services;
this.silo = silo;
Expand Down Expand Up @@ -42,7 +42,7 @@ public async Task StopAsync(CancellationToken cancellationToken)
try
{
this.applicationLifetime?.StopApplication();
await silo.StopAsync(cancellationToken);
await silo.StopAsync(cancellationToken).ConfigureAwait(false);
}
finally
{
Expand All @@ -60,7 +60,7 @@ public async ValueTask DisposeAsync()
this.isDisposing = true;
if (this.Services is IAsyncDisposable asyncDisposable)
{
await asyncDisposable.DisposeAsync();
await asyncDisposable.DisposeAsync().ConfigureAwait(false);
}
else if (this.Services is IDisposable disposable)
{
Expand Down
18 changes: 6 additions & 12 deletions src/Orleans.Runtime/Silo/Silo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,6 @@ public enum SiloType
/// <summary> SiloAddress for this silo. </summary>
public SiloAddress SiloAddress => this.siloDetails.SiloAddress;

/// <summary>
/// Silo termination event used to signal shutdown of this silo.
/// </summary>
public WaitHandle SiloTerminatedEvent // one event for all types of termination (shutdown, stop and fast kill).
=> ((IAsyncResult)this.siloTerminatedTask.Task).AsyncWaitHandle;

public Task SiloTerminated { get { return this.siloTerminatedTask.Task; } } // one event for all types of termination (shutdown, stop and fast kill).

private bool isFastKilledNeeded = false; // Set to true if something goes wrong in the shutdown/stop phase
Expand Down Expand Up @@ -604,19 +598,22 @@ public async Task StopAsync(CancellationToken cancellationToken)
while (!this.SystemStatus.Equals(SystemStatus.Terminated))
{
logger.Info(ErrorCode.WaitingForSiloStop, "Waiting {0} for termination to complete", pause);
await Task.Delay(pause);
await Task.Delay(pause).ConfigureAwait(false);
}

await this.SiloTerminated;
await this.SiloTerminated.ConfigureAwait(false);
return;
}

try
{
await this.scheduler.QueueTask(() => this.siloLifecycle.OnStop(cancellationToken), this.lifecycleSchedulingSystemTarget);
await this.scheduler.QueueTask(() => this.siloLifecycle.OnStop(cancellationToken), this.lifecycleSchedulingSystemTarget).ConfigureAwait(false);
}
finally
{
// Signal to all awaiters that the silo has terminated.
await Task.Run(() => this.siloTerminatedTask.TrySetResult(0)).ConfigureAwait(false);

SafeExecute(scheduler.Stop);
SafeExecute(scheduler.PrintStatistics);
}
Expand Down Expand Up @@ -653,9 +650,6 @@ private Task OnRuntimeInitializeStop(CancellationToken ct)

SafeExecute(() => this.SystemStatus = SystemStatus.Terminated);

// Setting the event should be the last thing we do.
// Do nothing after that!
this.siloTerminatedTask.SetResult(0);
return Task.CompletedTask;
}

Expand Down

0 comments on commit b56da8f

Please sign in to comment.