From ec1626b74601606799d82e9ba6020f48e86a8b24 Mon Sep 17 00:00:00 2001 From: Patrik Nordwall Date: Fri, 24 May 2013 15:38:24 +0200 Subject: [PATCH] Start heartbeatSender after Welcome, see #3388 * Otherwise, if the Welcome message is lost, other nodes in the cluster will send HeartbeatRequest and it will start sending heartbeats without being a real member and the lost Welcome is not detected by the other members in the cluster --- .../main/scala/akka/cluster/ClusterDaemon.scala | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/akka-cluster/src/main/scala/akka/cluster/ClusterDaemon.scala b/akka-cluster/src/main/scala/akka/cluster/ClusterDaemon.scala index c0d6ac9b4c..0ee125eecb 100644 --- a/akka-cluster/src/main/scala/akka/cluster/ClusterDaemon.scala +++ b/akka-cluster/src/main/scala/akka/cluster/ClusterDaemon.scala @@ -241,9 +241,6 @@ private[cluster] final class ClusterCoreDaemon(publisher: ActorRef) extends Acto private def clusterCore(address: Address): ActorSelection = context.actorSelection(RootActorPath(address) / "system" / "cluster" / "core" / "daemon") - context.actorOf(Props[ClusterHeartbeatSender]. - withDispatcher(UseDispatcher), name = "heartbeatSender") - import context.dispatcher // start periodic gossip to random nodes in cluster @@ -304,6 +301,14 @@ private[cluster] final class ClusterCoreDaemon(publisher: ActorRef) extends Acto } } + def becomeInitialized(): Unit = { + // start heartbeatSender here, and not in constructor to make sure that + // heartbeating doesn't start before Welcome is received + context.actorOf(Props[ClusterHeartbeatSender]. + withDispatcher(UseDispatcher), name = "heartbeatSender") + context.become(initialized) + } + def initialized: Actor.Receive = { case msg: GossipEnvelope ⇒ receiveGossip(msg) case msg: GossipStatus ⇒ receiveGossipStatus(msg) @@ -384,7 +389,7 @@ private[cluster] final class ClusterCoreDaemon(publisher: ActorRef) extends Acto } if (address == selfAddress) { - context.become(initialized) + becomeInitialized() joining(selfUniqueAddress, cluster.selfRoles) } else { val joinDeadline = RetryUnsuccessfulJoinAfter match { @@ -457,7 +462,7 @@ private[cluster] final class ClusterCoreDaemon(publisher: ActorRef) extends Acto publish(latestGossip) if (from != selfUniqueAddress) gossipTo(from, sender) - context.become(initialized) + becomeInitialized() } }