From 2fdf7c9e9bc98f4c0370ae1cc22f4fb6dea56271 Mon Sep 17 00:00:00 2001 From: "AndyChen(Jingzhang)" Date: Wed, 28 Feb 2024 16:15:01 +0800 Subject: [PATCH] fix: proper path when promise actor terminated quickly (#1156) --- .../org/apache/pekko/pattern/AskSpec.scala | 23 +++++++++++++++++++ .../org/apache/pekko/pattern/AskSupport.scala | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/actor-tests/src/test/scala/org/apache/pekko/pattern/AskSpec.scala b/actor-tests/src/test/scala/org/apache/pekko/pattern/AskSpec.scala index 2fced77bd00..e84777167b5 100644 --- a/actor-tests/src/test/scala/org/apache/pekko/pattern/AskSpec.scala +++ b/actor-tests/src/test/scala/org/apache/pekko/pattern/AskSpec.scala @@ -266,6 +266,29 @@ class AskSpec extends PekkoSpec(""" val (promiseActorRefForSelection, "ask") = p.expectMsgType[(ActorRef, String)]: @unchecked promiseActorRefForSelection.path.name should startWith("_user_myName") } + + "proper path when promise actor terminated" in { + implicit val timeout: Timeout = Timeout(300 millis) + val p = TestProbe() + + val act = system.actorOf(Props(new Actor { + def receive = { + case _ => + val senderRef: ActorRef = sender() + senderRef ! "complete" + p.ref ! senderRef + } + }), "pathPrefix") + + val f = (act ? "ask").mapTo[String] + val promiseActorRef = p.expectMsgType[ActorRef]: @unchecked + + // verify ask complete + val completed = f.futureValue + completed should ===("complete") + // verify path was proper + promiseActorRef.path.toString should include("pathPrefix") + } } } diff --git a/actor/src/main/scala/org/apache/pekko/pattern/AskSupport.scala b/actor/src/main/scala/org/apache/pekko/pattern/AskSupport.scala index 1cd660af22f..18f1ccc7008 100644 --- a/actor/src/main/scala/org/apache/pekko/pattern/AskSupport.scala +++ b/actor/src/main/scala/org/apache/pekko/pattern/AskSupport.scala @@ -604,7 +604,7 @@ private[pekko] final class PromiseActorRef( case StoppedWithPath(p) => p case Stopped => // even if we are already stopped we still need to produce a proper path - updateState(Stopped, StoppedWithPath(provider.tempPath())) + updateState(Stopped, StoppedWithPath(provider.tempPath(refPathPrefix))) path case Registering => path // spin until registration is completed case unexpected => throw new IllegalStateException(s"Unexpected state: $unexpected")