Ask Pattern Timeout Limits in Akka 2.6.x: What Happens to Late Replies?
0 reputation · 23 Jul 2020, 16:37 UTC
0 reputation · 23 Jul 2020, 16:37 UTC
When using Akka’s ask pattern, a Future is returned that completes with a Failure if the actor does not reply within the specified timeout. However, if the actor sends a reply after the timeout has elapsed, the Future is already failed and the reply is not observed by the caller. The documentation notes that such late replies are “dropped,” but it does not explicitly state whether they are routed to the dead‑letter mailbox or simply discarded. Furthermore, it is unclear whether the actor still receives the late message in its mailbox and can process it, or if the message is intercepted by the ask pattern’s internal logic before reaching the actor.
Understanding this behavior is critical for designing robust systems where actors may occasionally be slow or the timeout is misconfigured. The key unresolved questions are:
32775 reputation · 24 Jul 2020, 02:55 UTC
When the ask timeout expires in Akka 2.6.x, the temporary internal actor created for the ask is stopped and the returned Future is completed with an akka.pattern.AskTimeoutException. Any reply that arrives after that point is treated as an unhandled message; because the temporary actor no longer exists, the message is forwarded to the system’s dead‑letter mailbox. The original sender sees only the timeout failure and does not receive a second notification for the late reply.
context.stop(self).The internal promise actor’s mailbox is drained when it is stopped; any message that arrives after the stop is not processed by the actor’s behavior but is automatically redirected to system.deadLetters. Consequently, the target actor never sees the late reply because the message never reaches its mailbox – it is intercepted by the stopping logic before being delivered.
akka.pattern.ask with a timeout shorter than the delay (e.g., 100 ms).Future and verify it fails with AskTimeoutException.akka.log-dead-letters = on) and check the event log for a dead‑letter entry containing the delayed reply message.If the dead‑letter log shows the delayed reply, the behavior described above is confirmed. No further configuration is needed to alter this outcome.
Answers assume Akka version 2.6.x (the 2.6 series). The behavior is consistent across Scala and Java APIs. If you are using a different Akka version, verify the internal promise actor’s lifecycle, as earlier versions may have differed.
Use comments to ask for clarification. Post a solution as an answer.
4,930 reputation · 23 Jul 2020, 16:50 UTC
When the ask timeout fires, the temporary promise actor is stopped via context.stop(self). At that point any messages already in its mailbox are not processed; they are immediately redirected to the system’s deadLetter queue, just like messages that arrive after the stop. Consequently, a reply that the target actor sends after the timeout is never delivered to the target actor either, because the ask pattern never forwards the message – it is intercepted by the stopped internal actor’s mailbox handling and dead‑lettered. This behavior is not configurable in Akka 2.6.x.