Skip to content

Commit

Permalink
unregister AppDomain.ProcessExit event handler after ActorSystem term…
Browse files Browse the repository at this point in the history
…inates (akkadotnet#3846)

* close akkadotnet#3735 - unregister AppDomain.ProcessExit event handler after ActorSystem terminates

* fixed typo on save
  • Loading branch information
Aaronontheweb authored Feb 28, 2020
1 parent fc687b5 commit ad50778
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/core/Akka/Actor/CoordinatedShutdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -673,12 +673,10 @@ internal static void InitClrHook(ActorSystem system, Config conf, CoordinatedShu
var runByClrShutdownHook = conf.GetBoolean("run-by-clr-shutdown-hook", false);
if (runByClrShutdownHook)
{
var exitTask = TerminateOnClrExit(coord);
// run all hooks during termination sequence
AppDomain.CurrentDomain.ProcessExit += (sender, args) =>
{
// have to block, because if this method exits the process exits.
coord.RunClrHooks().Wait(coord.TotalTimeout);
};
AppDomain.CurrentDomain.ProcessExit += exitTask;
system.WhenTerminated.ContinueWith(tr => { AppDomain.CurrentDomain.ProcessExit -= exitTask; });

coord.AddClrShutdownHook(() =>
{
Expand All @@ -702,5 +700,14 @@ internal static void InitClrHook(ActorSystem system, Config conf, CoordinatedShu
});
}
}

private static EventHandler TerminateOnClrExit(CoordinatedShutdown coord)
{
return (sender, args) =>
{
// have to block, because if this method exits the process exits.
coord.RunClrHooks().Wait(coord.TotalTimeout);
};
}
}
}

0 comments on commit ad50778

Please sign in to comment.