Skip to content

Make sure AkkaHostedService failures are always visible#494

Merged
Aaronontheweb merged 3 commits into
akkadotnet:devfrom
Aaronontheweb:resolve-470-no-silent-failure
Oct 1, 2024
Merged

Make sure AkkaHostedService failures are always visible#494
Aaronontheweb merged 3 commits into
akkadotnet:devfrom
Aaronontheweb:resolve-470-no-silent-failure

Conversation

@Aaronontheweb
Copy link
Copy Markdown
Member

@Aaronontheweb Aaronontheweb commented Sep 16, 2024

Changes

close #470 - application crashes and exits should always be explicitly logged someplace where they can be seen regardless of logging configuration.

Checklist

For significant changes, please ensure that the following have been completed (delete if not relevant):

close akkadotnet#470 - application crashes and exits should always be explicitly logged someplace where they can be seen regardless of logging configuration.
@Aaronontheweb Aaronontheweb added logging Logging support for Akka.Hosting. dx Developer Experience / usability issues. labels Sep 16, 2024
Comment thread src/Akka.Hosting/AkkaHostedService.cs Outdated
Logger.Log(LogLevel.Critical, ex, "Unable to start AkkaHostedService - shutting down application");

// resolve https://github.com/akkadotnet/Akka.Hosting/issues/470 - never allow failures to be silent
Console.WriteLine($"Unable to start AkkaHostedService due to [{ex}] - shutting down application");
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ensure that this gets logged regardless of how the MSFT.EXT.Logger inputs have been configured

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think for exception, it should always be added at the end, because the stack trace will screw up the string formatting.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Or we can change that to "due to [{ex.Message}] - shutting down application.\nCause: {ex}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

or maybe we should just re-throw the exception as a new exception and let MS.EXT.Hosting deal with it.

Copy link
Copy Markdown
Contributor

@Arkatufus Arkatufus left a comment

Choose a reason for hiding this comment

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

I think this should be changed a bit

Comment thread src/Akka.Hosting/AkkaHostedService.cs Outdated
Logger.Log(LogLevel.Critical, ex, "Unable to start AkkaHostedService - shutting down application");

// resolve https://github.com/akkadotnet/Akka.Hosting/issues/470 - never allow failures to be silent
Console.WriteLine($"Unable to start AkkaHostedService due to [{ex}] - shutting down application");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think for exception, it should always be added at the end, because the stack trace will screw up the string formatting.

Comment thread src/Akka.Hosting/AkkaHostedService.cs Outdated
Logger.Log(LogLevel.Critical, ex, "Unable to start AkkaHostedService - shutting down application");

// resolve https://github.com/akkadotnet/Akka.Hosting/issues/470 - never allow failures to be silent
Console.WriteLine($"Unable to start AkkaHostedService due to [{ex}] - shutting down application");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Or we can change that to "due to [{ex.Message}] - shutting down application.\nCause: {ex}"

Comment thread src/Akka.Hosting/AkkaHostedService.cs Outdated
Logger.Log(LogLevel.Critical, ex, "Unable to start AkkaHostedService - shutting down application");

// resolve https://github.com/akkadotnet/Akka.Hosting/issues/470 - never allow failures to be silent
Console.WriteLine($"Unable to start AkkaHostedService due to [{ex}] - shutting down application");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

or maybe we should just re-throw the exception as a new exception and let MS.EXT.Hosting deal with it.

Copy link
Copy Markdown
Member Author

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

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

Changes look good @Arkatufus

var capturedException = ExceptionDispatchInfo.Capture(ex);
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(3));
await StopAsync(cts.Token);
capturedException.Throw();
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dx Developer Experience / usability issues. logging Logging support for Akka.Hosting.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants