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

Make sure AkkaHostedService failures are always visible #494

Merged

Conversation

Aaronontheweb
Copy link
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
@@ -72,6 +72,9 @@ async Task TerminationHook()
catch (Exception ex)
{
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
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
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
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
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
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

@@ -72,6 +72,9 @@ async Task TerminationHook()
catch (Exception ex)
{
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
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.

@@ -72,6 +72,9 @@ async Task TerminationHook()
catch (Exception ex)
{
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
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}"

@@ -72,6 +72,9 @@ async Task TerminationHook()
catch (Exception ex)
{
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
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
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
Member Author

Choose a reason for hiding this comment

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

LGTM

@Aaronontheweb Aaronontheweb enabled auto-merge (squash) October 1, 2024 16:24
@Aaronontheweb Aaronontheweb merged commit 401e020 into akkadotnet:dev Oct 1, 2024
2 checks passed
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