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

enable ChannelTaskScheduler to work inside Akka.Cluster without causing errors inside /system actors #5861

Merged
2 changes: 1 addition & 1 deletion src/core/Akka.Cluster/ClusterDaemon.cs
Expand Up @@ -895,7 +895,7 @@ private void CreateChildren(Cluster cluster)
_cluster = cluster;
_coreSupervisor = Context.ActorOf(Props.Create<ClusterCoreSupervisor>(), "core");

Context.ActorOf(ClusterHeartbeatReceiver.Props(() => _cluster), "heartbeatReceiver");
Copy link
Member Author

Choose a reason for hiding this comment

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

Avoid creating a delegate for the Lazy<Cluster> that we're removing from the HeartbeatReceiver

Context.ActorOf(ClusterHeartbeatReceiver.Props(cluster), "heartbeatReceiver");
}

protected override void PostStop()
Expand Down
14 changes: 7 additions & 7 deletions src/core/Akka.Cluster/ClusterHeartbeat.cs
Expand Up @@ -26,16 +26,16 @@ internal sealed class ClusterHeartbeatReceiver : UntypedActor
{
// Important - don't use Cluster.Get(Context.System) in constructor because that would
// cause deadlock. See startup sequence in ClusterDaemon.
private readonly Lazy<Cluster> _cluster;
Copy link
Member Author

Choose a reason for hiding this comment

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

No real reason for a Lazy<Cluster> here since we're already receiving an instance in this actor's constructor at the time it's created.

private readonly Cluster _cluster;

public bool VerboseHeartbeat => _cluster.Value.Settings.VerboseHeartbeatLogging;
public bool VerboseHeartbeat => _cluster.Settings.VerboseHeartbeatLogging;

/// <summary>
/// TBD
/// </summary>
public ClusterHeartbeatReceiver(Func<Cluster> getCluster)
public ClusterHeartbeatReceiver(Cluster cluster)
{
_cluster = new Lazy<Cluster>(getCluster);
_cluster = cluster;
}

protected override void OnReceive(object message)
Expand All @@ -44,8 +44,8 @@ protected override void OnReceive(object message)
{
case ClusterHeartbeatSender.Heartbeat hb:
// TODO log the sequence nr once serializer is enabled
if(VerboseHeartbeat) _cluster.Value.CurrentInfoLogger.LogDebug("Heartbeat from [{0}]", hb.From);
Sender.Tell(new ClusterHeartbeatSender.HeartbeatRsp(_cluster.Value.SelfUniqueAddress,
if(VerboseHeartbeat) _cluster.CurrentInfoLogger.LogDebug("Heartbeat from [{0}]", hb.From);
Sender.Tell(new ClusterHeartbeatSender.HeartbeatRsp(_cluster.SelfUniqueAddress,
hb.SequenceNr, hb.CreationTimeNanos));
break;
default:
Expand All @@ -54,7 +54,7 @@ protected override void OnReceive(object message)
}
}

public static Props Props(Func<Cluster> getCluster)
public static Props Props(Cluster getCluster)
{
return Akka.Actor.Props.Create(() => new ClusterHeartbeatReceiver(getCluster));
}
Expand Down