He-Pin opened a new issue, #3258:
URL: https://github.com/apache/pekko/issues/3258
### Motivation
The fix for timer message loss during stash/unstash (`Timers.scala:58`) only
covers actors using the `Stash` trait. Actors using `UnboundedStash` or
`UnrestrictedStash` still lose timer messages because the `currentMessage`
rewrite is skipped.
### Current Behavior
`actor/src/main/scala/org/apache/pekko/actor/Timers.scala:58-61`:
```scala
if (this.isInstanceOf[Stash]) {
actorCell.currentMessage = actorCell.currentMessage.copy(message = m)
}
```
The trait hierarchy (`Stash.scala:71-82`):
```
Stash extends UnrestrictedStash (with RequiresMessageQueue[...])
UnboundedStash extends UnrestrictedStash (with RequiresMessageQueue[...])
UnrestrictedStash extends Actor with StashSupport
```
`Stash` and `UnboundedStash` are **siblings** — neither extends the other.
The `isInstanceOf[Stash]` guard returns `false` for actors mixing in
`UnboundedStash` or `UnrestrictedStash` directly.
### What Happens Without the Fix
1. Timer fires, wraps user message in `TimerMsg`
2. `aroundReceive` unwraps `TimerMsg`, calls user's `receive` with the
actual message
3. User calls `stash()` — but `StashSupport.stash()` reads
`actorCell.currentMessage` which still contains the `TimerMsg` wrapper
4. On `unstashAll()`, the `TimerMsg` wrapper is re-enqueued
5. `aroundReceive` intercepts it again, `interceptTimerMsg` discards it
(single-shot timer already removed, or stale generation for repeating)
6. **Message is lost**
### Fix
Change `this.isInstanceOf[Stash]` to `this.isInstanceOf[StashSupport]` to
cover all three public stash traits.
### Not Affected
Typed `StashBuffer` is not affected — timer messages are unwrapped at
`ActorAdapter.scala:136-138` before reaching the behavior.
### Environment
- Pekko Actor (any version)
- `Timers.scala:58`
### References
None
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]