Skip to content

Commit

Permalink
close akkadotnet#48 - fixed source of NRE upon shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaronontheweb committed May 19, 2022
1 parent cc417e8 commit 09d23bd
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Akka.Hosting/AkkaHostedService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Akka.Hosting
internal sealed class AkkaHostedService : IHostedService
{
private ActorSystem _actorSystem;
private CoordinatedShutdown _coordinatedShutdown; // grab a reference to CoordinatedShutdown early
private readonly IServiceProvider _serviceProvider;
private readonly AkkaConfigurationBuilder _configurationBuilder;
private readonly IHostApplicationLifetime _hostApplicationLifetime;
Expand All @@ -33,6 +34,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
try
{
_actorSystem = _serviceProvider.GetRequiredService<ActorSystem>();
_coordinatedShutdown = CoordinatedShutdown.Get(_actorSystem);
await _configurationBuilder.StartAsync(_actorSystem);

async Task TerminationHook()
Expand All @@ -57,7 +59,7 @@ async Task TerminationHook()
public async Task StopAsync(CancellationToken cancellationToken)
{
// run full CoordinatedShutdown on the Sys
await CoordinatedShutdown.Get(_actorSystem).Run(CoordinatedShutdown.ClrExitReason.Instance)
await _coordinatedShutdown.Run(CoordinatedShutdown.ClrExitReason.Instance)
.ConfigureAwait(false);
}
}
Expand Down

0 comments on commit 09d23bd

Please sign in to comment.