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

Stop DeadLetterListener on terminate if LogDeadLettersDuringShutdown is disabled #4042

Merged
merged 1 commit into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -2878,6 +2878,7 @@ namespace Akka.Event
public DeadLetterListener() { }
protected override void PostRestart(System.Exception reason) { }
protected override void PostStop() { }
protected override void PreRestart(System.Exception reason, object message) { }
protected override void PreStart() { }
protected override bool Receive(object message) { }
}
Expand Down
20 changes: 20 additions & 0 deletions src/core/Akka.Tests/Actor/ActorSystemSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,26 @@ public void Allow_valid_names()
.Terminate();
}

[Fact]
public void Log_dead_letters()
{
var sys = ActorSystem.Create("LogDeadLetters", ConfigurationFactory.ParseString("akka.loglevel=INFO")
.WithFallback(DefaultConfig));

try
{
var a = sys.ActorOf(Props.Create<Terminater>());

var eventFilter = new EventFilterFactory(new TestKit.Xunit2.TestKit(sys));
eventFilter.Info(contains: "not delivered").Expect(1, () =>
{
a.Tell("run");
a.Tell("boom");
});
}
finally { Shutdown(sys); }
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Just a missing test

[Fact]
public void Block_until_exit()
{
Expand Down
2 changes: 2 additions & 0 deletions src/core/Akka/Actor/Internal/ActorSystemImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@ public override void RegisterOnTermination(Action code)
public override Task Terminate()
{
Log.Debug("System shutdown initiated");
if (!Settings.LogDeadLettersDuringShutdown && _logDeadLetterListener != null)
Stop(_logDeadLetterListener);
_provider.Guardian.Stop();
return WhenTerminated;
}
Expand Down
23 changes: 13 additions & 10 deletions src/core/Akka/Event/DeadLetterListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ public class DeadLetterListener : ActorBase
private int _count;

/// <summary>
/// TBD
/// Don't re-subscribe, skip call to preStart
/// </summary>
/// <param name="reason">TBD</param>
protected override void PostRestart(Exception reason)
{
}

/// <summary>
/// Don't remove subscription, skip call to postStop, no children to stop
/// </summary>
protected override void PreRestart(Exception reason, object message)
{
}

/// <summary>
/// TBD
/// </summary>
Expand Down Expand Up @@ -55,7 +61,7 @@ protected override bool Receive(object message)
var rcp = deadLetter.Recipient;

_count++;

var done = _maxCount != int.MaxValue && _count >= _maxCount;
var doneMsg = done ? ", no more dead letters will be logged" : "";

Expand All @@ -65,15 +71,12 @@ protected override bool Receive(object message)
var sndPath = snd == ActorRefs.NoSender ? "NoSender" : snd.Path.ToString();

_eventStream.Publish(new Info(rcpPath, rcp.GetType(),
string.Format("Message {0} from {1} to {2} was not delivered. {3} dead letters encountered.{4}",
deadLetter.Message.GetType().Name, sndPath, rcpPath, _count, doneMsg)));
}

if (done)
{
((IInternalActorRef) Self).Stop();
$"Message [{deadLetter.Message.GetType().Name}] from {sndPath} to {rcpPath} was not delivered. [{_count}] dead letters encountered {doneMsg}." +
"This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' " +
"and 'akka.log-dead-letters-during-shutdown'."));
}

if (done) Context.Stop(Self);
return true;
}
}
Expand Down