He-Pin opened a new issue, #3213:
URL: https://github.com/apache/pekko/issues/3213

   ### Motivation
   
   在 typed EventSourcedBehavior 加载 snapshot 阶段,如果 actor 被停止,用户的 PostStop signal 
handler 不会被调用。这会导致用户无法在停止时执行清理逻辑。
   
   ### 当前代码行为
   
   `ReplayingSnapshot.scala` 中的 signal handler:
   
   ```scala
   // ReplayingSnapshot.scala:88-94
   .receiveSignal(returnPermitOnStop.orElse {
     case (_, PostStop) => Behaviors.stopped
     ...
   })
   ```
   
   `returnPermitOnStop`(定义在 `ExternalInteractions.scala:148-156`)直接捕获 
PostStop,调用 `tryReturnRecoveryPermit` 并返回 `Behaviors.stopped`,但**不调用用户的 
`setup.onSignal`**。
   
   对比 `ReplayingEvents.scala:122-128`,在事件回放阶段 PostStop 会调用用户的 signal handler。
   
   ### 预期行为
   
   所有阶段的 PostStop 都应该调用用户注册的 signal handler(通过 `setup.onSignal`),确保用户清理逻辑始终执行。
   
   ### 代码证据
   
   - 
`persistence-typed/src/main/scala/org/apache/pekko/persistence/typed/internal/ReplayingSnapshot.scala:88-94`
 — snapshot 加载阶段的 signal handler
   - 
`persistence-typed/src/main/scala/org/apache/pekko/persistence/typed/internal/ExternalInteractions.scala:148-156`
 — `returnPermitOnStop` 实现
   - 
`persistence-typed/src/main/scala/org/apache/pekko/persistence/typed/internal/ReplayingEvents.scala:122-128`
 — 对比:事件回放阶段正确调用用户 handler
   
   ### 复现方式
   
   ```scala
   val behavior = EventSourcedBehavior[Command, Event, State](
     persistenceId = PersistenceId("test", "1"),
     emptyState = State(),
     commandHandler = ...,
     eventHandler = ...
   ).receiveSignal {
     case (_, PostStop) => println("CLEANUP") // 在 snapshot 加载期间 stop 时不会打印
   }
   ```
   
   ### 影响范围
   
   - 模块:`pekko-persistence-typed`
   - 影响在 snapshot 加载期间 actor 被停止的场景(如 graceful shutdown、超时)
   - 用户清理逻辑(关闭资源、释放锁等)不会被执行


-- 
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]

Reply via email to