Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix leaky coordinated shutdown #5816

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/Akka/Actor/ActorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ private static ActorSystem CreateAndStartSystem(string name, Config withFallback
/// </returns>
public abstract Task Terminate();

internal abstract void FinalTerminate();
internal abstract Task FinalTerminate();

/// <summary>
/// Returns a task which will be completed after the <see cref="ActorSystem"/> has been
Expand Down
10 changes: 6 additions & 4 deletions src/core/Akka/Actor/CoordinatedShutdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ private ClusterJoinUnsuccessfulReason() { }
/// <summary>
/// The <see cref="ActorSystem"/>
/// </summary>
public ExtendedActorSystem System { get; }
public ExtendedActorSystem System { get; private set; }

/// <summary>
/// The set of named <see cref="Phase"/>s that will be executed during coordinated shutdown.
Expand All @@ -261,7 +261,7 @@ private ClusterJoinUnsuccessfulReason() { }
/// <summary>
/// INTERNAL API
/// </summary>
internal ILoggingAdapter Log { get; }
internal ILoggingAdapter Log { get; private set; }

private readonly HashSet<string> _knownPhases;

Expand Down Expand Up @@ -653,13 +653,15 @@ internal static void InitPhaseActorSystemTerminate(ActorSystem system, Config co

if (terminateActorSystem)
{
system.FinalTerminate();
return system.Terminate().ContinueWith(tr =>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This potentially an infinite loop call, if the call came from ActorSystem.Terminate() in the first place.

return system.FinalTerminate().ContinueWith(tr =>
{
if (exitClr && !coord._runningClrHook)
{
Environment.Exit(0);
}

coord.System = null;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clear the reference to the ActorSystem to prevent a circular reference, preventing the ActorSystem from being garbage collected afterward.

coord.Log = null;
return Done.Instance;
});
}
Expand Down
11 changes: 5 additions & 6 deletions src/core/Akka/Actor/Internal/ActorSystemImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -525,20 +525,19 @@ public override Task Terminate()
{
if(Settings.CoordinatedShutdownRunByActorSystemTerminate)
{
CoordinatedShutdown.Get(this).Run(CoordinatedShutdown.ActorSystemTerminateReason.Instance);
} else
{
FinalTerminate();
return CoordinatedShutdown.Get(this)
.Run(CoordinatedShutdown.ActorSystemTerminateReason.Instance);
}
return WhenTerminated;
return FinalTerminate();
}

internal override void FinalTerminate()
internal override Task FinalTerminate()
{
Log.Debug("System shutdown initiated");
if (!Settings.LogDeadLettersDuringShutdown && _logDeadLetterListener != null)
Stop(_logDeadLetterListener);
_provider.Guardian.Stop();
return WhenTerminated;
}

/// <summary>
Expand Down