fix: typed actor dead letter address (#29795)#32104
Merged
johanandren merged 6 commits intoakka:mainfrom Sep 18, 2023
Merged
Conversation
Roiocam
commented
Sep 17, 2023
|
|
||
| val deadLettersRef = system.classicSystem.deadLetters | ||
| deadLetter.recipient shouldNot equal(deadLettersRef) | ||
| deadLetter.recipient should equal(ActorRefAdapter.toClassic(actor)) |
Contributor
Author
There was a problem hiding this comment.
Can't use actor.toClassic, There should be a better way to optimize this line.
johanandren
approved these changes
Sep 18, 2023
leviramsey
reviewed
Sep 20, 2023
| val answer: Future[String] = actor.ask(Foo("bar", _)) | ||
| val result = answer.failed.futureValue | ||
| result shouldBe a[TimeoutException] | ||
| result.getMessage should startWith("Ask timed out on") |
Contributor
There was a problem hiding this comment.
This test seems flaky... there's a race between news of the actor stopping and the ask. If one side wins, the message will start with this, but if the other wins, it will start with "Recipient... had already been terminated."
Contributor
Author
There was a problem hiding this comment.
Yep, It is also has a fix commit on #32107
This was referenced Sep 20, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Attach the necessary information before sending the message to DeadLetter to correctly display the destination in the DeadLetter.
References #29795
How does this PR fix work?
In classic Actors, when an Actor dies, its Mailbox is "swap" to a
deadLetterMailboxMailbox.When an Actor sends a message to another ActorRef, it essentially enqueues the message to that Actor's mailbox.
When an Actor sends a message to a dead Actor, it means that the message would enqueue to the "deadLetterMailbox",the dead mailbox will transform the message into a DeadLetter event and then publish it to the EventBus. This is how DeadLetters work in classic Actors.
In Typed actor, it basiclly same, but the
sendervariable cannot be passed implicitly.In the Ask pattern, there are some differences. When an Actor uses ask to request another Actor, it essentially creates a temporary PromiseActorRef to receive the response from the target Actor.
When the PromiseActorRef receives a
tellcall, it checks if the current Future has already completed and, if so, emits a DeadLetter event. This is done to ensure consistent behavior with the tell method (i.e., sending DeadLetter events to the EventBus via DeadLetterActorRef).However, the PromiseActorRef directly sends the message without transforming it into a DeadLetter event, resulting in distorted logs.
This PR converts the message into a DeadLetter event before sending it from PromiseActorRef to DeadLetterActorRef.