diff --git a/akka-actor/src/main/scala/akka/actor/ActorRef.scala b/akka-actor/src/main/scala/akka/actor/ActorRef.scala index b93b35aa76..bd2ee513fd 100644 --- a/akka-actor/src/main/scala/akka/actor/ActorRef.scala +++ b/akka-actor/src/main/scala/akka/actor/ActorRef.scala @@ -550,13 +550,28 @@ private[akka] class VirtualPathContainer( def addChild(name: String, ref: InternalActorRef): Unit = { children.put(name, ref) match { case null ⇒ // okay - case old ⇒ log.warning("{} replacing child {} ({} -> {})", path, name, old, ref) + case old ⇒ + // this can happen from RemoteSystemDaemon if a new child is created + // before the old is removed from RemoteSystemDaemon children + log.debug("{} replacing child {} ({} -> {})", path, name, old, ref) } } def removeChild(name: String): Unit = if (children.remove(name) eq null) log.warning("{} trying to remove non-child {}", path, name) + /** + * Remove a named child if it matches the ref. + */ + protected def removeChild(name: String, ref: ActorRef): Unit = { + val current = getChild(name) + if (current eq null) + log.warning("{} trying to remove non-child {}", path, name) + else if (current == ref) + children.remove(name, current) // remove when same value + + } + def getChild(name: String): InternalActorRef = children.get(name) override def getChild(name: Iterator[String]): InternalActorRef = { diff --git a/akka-remote/src/main/scala/akka/remote/RemoteDaemon.scala b/akka-remote/src/main/scala/akka/remote/RemoteDaemon.scala index 9947fe4f61..38291f0f7c 100644 --- a/akka-remote/src/main/scala/akka/remote/RemoteDaemon.scala +++ b/akka-remote/src/main/scala/akka/remote/RemoteDaemon.scala @@ -83,7 +83,7 @@ private[akka] class RemoteSystemDaemon( override def sendSystemMessage(message: SystemMessage): Unit = message match { case DeathWatchNotification(child: ActorRefWithCell with ActorRefScope, _, _) if child.isLocal ⇒ terminating.locked { - removeChild(child.path.elements.drop(1).mkString("/")) + removeChild(child.path.elements.drop(1).mkString("/"), child) terminationHookDoneWhenNoChildren() } case _ ⇒ super.sendSystemMessage(message)