akkadotnet/Akka.Hosting

Errors that occur during launch of `AkkaHostedService` get eaten / not logged

Closed this issue · 1 comments

Version Information
Version of Akka.NET? v1.5.15
Which Akka.NET Modules? Akka.Hosting

Describe the bug

Have the following code sample:

public static AkkaConfigurationBuilder AddIssueTrackingActor(this AkkaConfigurationBuilder builder)
    {
        return builder
            .AddHocon(
                $"custom-issue-tracking-mailbox {{ mailbox-type: \"{typeof(IssueTrackerMailbox).AssemblyQualifiedName}\" }}",
                HoconAddMode.Append)
            .WithActors((system, registry) =>
            {
                Actor.Props props = Akka.Actor.Props.Create<IssueTrackingActor>()
                    .WithMailbox("custom-issue-tracking-mailbox");
                IActorRef actor = system.ActorOf(props, "issue-tracking-actor");

                //BUG: we never register the IssueTrackingActor with the ActorRegistry
            })
            .AddStartup((system, registry) =>
            {
                // BUG part 2: attempt to resolve non-existent entry from registry; exception thrown
                IActorRef actor = registry.Get<IssueTrackingActor>();
                
                // Send the issues in reverse order of importance.
                // Worth bearing in mind: totally possible that a lower-priority item might get processed
                // before the higher priority ones if the actor gets scheduled and runs immediately - it's
                // not going to sit there and wait for the higher priority items to arrive before starting.
                actor.Tell(new Issue("Issue 3", "Description 3", IssuePriority.Low));
                actor.Tell(new Issue("Issue 2", "Description 2", IssuePriority.Medium));
                actor.Tell(new Issue("Issue 1", "Description 1", IssuePriority.High));
                actor.Tell(new Issue("Issue 0", "Description 1", IssuePriority.High));
                
            });
    }

You can see where I detailed the bugs on there - the registry.Get<IssueTrackingActor>(); call throws.

However, what I see when I run this without the debugger attached is just an immediate process exit with no indication that anything went wrong. This isn't a great user experience and we need to find some way of clearly communicating that a bad thing happened to the end-user.

Crashing the process and fast-exiting is probably ok, but the user has to be given an explanation for why this happened.

Expected behavior

Some kind of error message indicating what the problem was and why my process exited.

Actual behavior

Silent failure.

Screenshots
If applicable, add screenshots to help explain your problem.

Environment

Running via Rider F5 without the debugger attached - this where I get the silent exit.

When running via dotnet run on the console I get this instead:

image

Seems like everything else startup up and ran ok there, but still no error message for the failed behavior.

Try adding this:

var hostBuilder = new HostBuilder();
hostBuilder.ConfigureLogging(builder =>
{
    builder.AddConsole();
});