Skip to content
Merged
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
21 changes: 16 additions & 5 deletions src/core/Akka/Event/LoggingBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,10 @@ private void RemoveLogger(IActorRef logger)
var fullLoggerName = $"{loggerName} [{loggerType.FullName}]";
var logger = system.SystemActorOf(Props.Create(loggerType).WithDispatcher(system.Settings.LoggersDispatcher), loggerName);
var askTask = logger.Ask(new InitializeLogger(this), Timeout.InfiniteTimeSpan, _shutdownCts.Token);

askTask.ContinueWith(t =>

// Return the continuation task, not the ask task, so callers wait for
// the full initialization sequence including the "Logger started" message
var continuationTask = askTask.ContinueWith(t =>
{
// _shutdownCts was cancelled while this logger is still loading
if (t.IsCanceled)
Expand All @@ -215,7 +217,16 @@ private void RemoveLogger(IActorRef logger)
RemoveLogger(logger);
return;
}


// Ask operation failed with an exception
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.

Do this address your concern @Arkatufus ?

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.

LGTM

if (t.IsFaulted)
{
Publish(new Error(t.Exception, loggingBusName, GetType(),
$"Logger {fullLoggerName} failed to respond to initialization request. Stopping logger."));
RemoveLogger(logger);
return;
}

// Task ran to completion successfully
var response = t.Result;
if (response is not LoggerInitialized)
Expand All @@ -231,8 +242,8 @@ private void RemoveLogger(IActorRef logger)
_loggers.Add(logger);
SubscribeLogLevelAndAbove(LogLevel, logger);
Publish(new Debug(loggingBusName, GetType(), $"Logger {fullLoggerName} started"));
});
return (askTask, fullLoggerName);
}, TaskContinuationOptions.ExecuteSynchronously);
return (continuationTask, fullLoggerName);
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.

Return the continuation task and have waiters wait on that, versus the original task itself.

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.

Just noticed this now, but if askTask threw, the continuation would fail on var response = t.Result; and the logger would not be removed/unsubscribed. Maybe we need to check for t.IsFaulted too?

}

private string CreateLoggerName(Type actorClass)
Expand Down