diff --git a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.DotNet.verified.txt b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.DotNet.verified.txt
index 7cab961cc81..104827f2cf0 100644
--- a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.DotNet.verified.txt
+++ b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.DotNet.verified.txt
@@ -98,6 +98,7 @@ namespace Akka.Actor
public void CheckReceiveTimeout(bool reschedule = True) { }
protected void ClearActor(Akka.Actor.ActorBase actor) { }
protected void ClearActorCell() { }
+ [return: System.Runtime.CompilerServices.NullableAttribute(2)]
protected virtual Akka.Actor.ActorRestarted CreateActorRestartedEvent(System.Exception cause) { }
protected virtual Akka.Actor.ActorStarted CreateActorStartedEvent() { }
protected virtual Akka.Actor.ActorStopped CreateActorStoppedEvent() { }
diff --git a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.Net.verified.txt b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.Net.verified.txt
index f6e842c522f..9b8a28e3d35 100644
--- a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.Net.verified.txt
+++ b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.Net.verified.txt
@@ -98,6 +98,7 @@ namespace Akka.Actor
public void CheckReceiveTimeout(bool reschedule = True) { }
protected void ClearActor(Akka.Actor.ActorBase actor) { }
protected void ClearActorCell() { }
+ [return: System.Runtime.CompilerServices.NullableAttribute(2)]
protected virtual Akka.Actor.ActorRestarted CreateActorRestartedEvent(System.Exception cause) { }
protected virtual Akka.Actor.ActorStarted CreateActorStartedEvent() { }
protected virtual Akka.Actor.ActorStopped CreateActorStoppedEvent() { }
diff --git a/src/core/Akka/Actor/ActorCell.Children.cs b/src/core/Akka/Actor/ActorCell.Children.cs
index e54ffd48771..89a969c1b02 100644
--- a/src/core/Akka/Actor/ActorCell.Children.cs
+++ b/src/core/Akka/Actor/ActorCell.Children.cs
@@ -141,11 +141,9 @@ private string GetRandomActorName(string prefix = "$")
/// The child.
public void Stop(IActorRef child)
{
- ChildRestartStats stats;
- if (ChildrenContainer.TryGetByRef(child, out stats))
+ if (ChildrenContainer.TryGetByRef(child, out _))
{
- var repointableActorRef = child as RepointableActorRef;
- if (repointableActorRef == null || repointableActorRef.IsStarted)
+ if (child is not RepointableActorRef repointableActorRef || repointableActorRef.IsStarted)
{
while (true)
{
diff --git a/src/core/Akka/Actor/ActorCell.DefaultMessages.cs b/src/core/Akka/Actor/ActorCell.DefaultMessages.cs
index c888edb2759..434ef7ada7e 100644
--- a/src/core/Akka/Actor/ActorCell.DefaultMessages.cs
+++ b/src/core/Akka/Actor/ActorCell.DefaultMessages.cs
@@ -441,7 +441,7 @@ public void Restart(Exception cause)
///
/// Overrideable in order to support issues such as https://github.com/petabridge/phobos-issues/issues/82
///
- protected virtual ActorStarted CreateActorStartedEvent()
+ protected virtual ActorStarted? CreateActorStartedEvent()
{
return new ActorStarted(Self, Props.Type);
}
@@ -449,7 +449,7 @@ protected virtual ActorStarted CreateActorStartedEvent()
///
/// Overrideable in order to support issues such as https://github.com/petabridge/phobos-issues/issues/82
///
- protected virtual ActorStopped CreateActorStoppedEvent()
+ protected virtual ActorStopped? CreateActorStoppedEvent()
{
return new ActorStopped(Self, Props.Type);
}
@@ -466,8 +466,13 @@ private void Create(Exception? failure)
CheckReceiveTimeout();
if (System.Settings.DebugLifecycle)
Publish(new Debug(Self.Path.ToString(), created.GetType(), "Started (" + created + ")"));
- if(System.Settings.EmitActorTelemetry)
- System.EventStream.Publish(CreateActorStartedEvent());
+ if (System.Settings.EmitActorTelemetry)
+ {
+ var actorStarted = CreateActorStartedEvent();
+ if(actorStarted != null)
+ System.EventStream.Publish(actorStarted);
+ }
+
}
catch (Exception e)
{
diff --git a/src/core/Akka/Actor/ActorCell.FaultHandling.cs b/src/core/Akka/Actor/ActorCell.FaultHandling.cs
index 4546fa34c66..e7f32f606e8 100644
--- a/src/core/Akka/Actor/ActorCell.FaultHandling.cs
+++ b/src/core/Akka/Actor/ActorCell.FaultHandling.cs
@@ -290,9 +290,13 @@ private void FinishTerminate()
var pipeline = SystemImpl.ActorPipelineResolver.ResolvePipeline(a.GetType());
pipeline.BeforeActorIncarnated(a, this);
}
-
- if(System.Settings.EmitActorTelemetry)
- System.EventStream.Publish(CreateActorStoppedEvent());
+
+ if (System.Settings.EmitActorTelemetry)
+ {
+ var stopEvent = CreateActorStoppedEvent();
+ if (stopEvent is not null)
+ System.EventStream.Publish(stopEvent);
+ }
}
catch (Exception x)
{
@@ -350,8 +354,12 @@ private void FinishRecreate(Exception cause, ActorBase? failedActor)
if (System.Settings.DebugLifecycle)
Publish(new Debug(_self.Path.ToString(), freshActor.GetType(), "Restarted (" + freshActor + ")"));
- if(System.Settings.EmitActorTelemetry)
- System.EventStream.Publish(CreateActorRestartedEvent(cause));
+ if (System.Settings.EmitActorTelemetry)
+ {
+ var restartEvent = CreateActorRestartedEvent(cause);
+ if (restartEvent is not null)
+ System.EventStream.Publish(restartEvent);
+ }
// only after parent is up and running again do restart the children which were not stopped
foreach (var survivingChild in survivors)
@@ -378,7 +386,7 @@ private void FinishRecreate(Exception cause, ActorBase? failedActor)
///
/// Overrideable in order to support issues such as https://github.com/petabridge/phobos-issues/issues/82
///
- protected virtual ActorRestarted CreateActorRestartedEvent(Exception cause)
+ protected virtual ActorRestarted? CreateActorRestartedEvent(Exception cause)
{
return new ActorRestarted(Self, Props.Type, cause);
}