You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@pekko.apache.org by "He-Pin (via GitHub)" <gi...@apache.org> on 2026/06/28 16:09:13 UTC

[PR] fix: deliver stashed timer messages for UnboundedStash and UnrestrictedStash (#3258) [pekko]

He-Pin opened a new pull request, #3264:
URL: https://github.com/apache/pekko/pull/3264

   ### Motivation
   
   `Timers` rewrites `actorCell.currentMessage` to the **unwrapped** timer message
   before invoking the user's `receive`, so that `stash()` (which reads
   `currentMessage` directly) captures the actual message rather than the internal
   `TimerMsg` wrapper.
   
   That rewrite was guarded by `this.isInstanceOf[Stash]`. But `Stash`,
   `UnboundedStash` and `UnrestrictedStash` are **siblings** — they all extend
   `UnrestrictedStash` / `StashSupport`, and `UnboundedStash`/`UnrestrictedStash`
   are **not** subtypes of `Stash`. So for an actor mixing in `UnboundedStash` or
   `UnrestrictedStash` directly, the guard was `false`, the rewrite was skipped,
   and `stash()` captured the `TimerMsg` wrapper. On `unstashAll()` the wrapper was
   intercepted again and discarded (the single-shot timer was already removed, or
   the generation was stale for a periodic timer), so **the message was lost**.
   
   The same guard also excluded the Java‑API stash actors (`AbstractActorWithStash`
   and friends, via `AbstractActorStashSupport`), which have the same problem.
   
   Fixes #3258.
   
   ### Modification
   
   - Guard the `currentMessage` rewrite with `this.isInstanceOf[StashSupport]`
     instead of `this.isInstanceOf[Stash]`. `StashSupport` is the common base of
     all stash‑capable actors (`Stash`, `UnboundedStash`, `UnrestrictedStash`, and
     the Java‑API stash classes), and it is exactly the set of actors whose
     `stash()` reads `currentMessage` — so it is the precise, correct boundary.
   - Expanded the explanatory comment so the sibling relationship and the
     re‑stash/lost‑message mechanism are clear (keeping the original `#24557`
     reference).
   
   ### Result
   
   - Timer messages stashed with `UnboundedStash` or `UnrestrictedStash` (and the
     Java‑API stash actors) are no longer lost on `unstashAll()`.
   - Behavior for `Stash` is unchanged, and non‑stashing actors are unaffected
     (the guard is still `false` for them).
   - The change is a method‑body change in `Timers.aroundReceive`; **no public API
     or binary‑compatibility change** (`actor / mimaReportBinaryIssues` is clean).
   
   ### Tests
   
   - `sbt "actor-tests/testOnly org.apache.pekko.actor.TimerSpec org.apache.pekko.actor.TimersAndStashSpec"`
     → all passed.
   - Added directional tests mirroring the existing `Stash` test, for
     `UnboundedStash` and `UnrestrictedStash` (the latter with an explicit
     deque‑based mailbox, since `UnrestrictedStash` does not declare
     `RequiresMessageQueue`). Both **fail before the fix** (the stashed timer
     message is lost: `expectMsg("scheduled")` times out) and pass after.
   - `sbt "actor/mimaReportBinaryIssues"` → no binary issues.
   
   ### References
   
   Fixes #3258
   
   ---
   
   This is an original contribution to Apache Pekko, made under the Apache License
   2.0 (i.e. the changes are now Apache licensed). No third-party or Akka-derived
   code is included.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] fix: deliver stashed timer messages for UnboundedStash and UnrestrictedStash (#3258) [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin merged PR #3264:
URL: https://github.com/apache/pekko/pull/3264


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] fix: deliver stashed timer messages for UnboundedStash and UnrestrictedStash (#3258) [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on PR #3264:
URL: https://github.com/apache/pekko/pull/3264#issuecomment-4826745354

   @pjfanning I think we can backport this to 1.7.0 ,wdyt


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] fix: deliver stashed timer messages for UnboundedStash and UnrestrictedStash (#3258) [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on code in PR #3264:
URL: https://github.com/apache/pekko/pull/3264#discussion_r3488198550


##########
actor/src/main/scala/org/apache/pekko/actor/Timers.scala:
##########
@@ -55,8 +55,12 @@ trait Timers extends Actor {
           case OptionVal.Some(m: AutoReceivedMessage) =>
             context.asInstanceOf[ActorCell].autoReceiveMessage(Envelope(m, self, context.system))
           case OptionVal.Some(m) =>
-            if (this.isInstanceOf[Stash]) {
-              // this is important for stash interaction, as stash will look directly at currentMessage #24557
+            if (this.isInstanceOf[StashSupport]) {

Review Comment:
   https://github.com/apache/pekko/blob/main/actor/src/main/scala/org/apache/pekko/actor/Stash.scala



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org