Terminated message ordering during ActorSystem termination with watched children
0 reputation · 02 Jun 2021, 05:07 UTC
Context
In Akka Typed, a parent actor that spawns a child and registers a watch via context.watch receives a Terminated signal when that child stops. The documentation specifies that stopping a parent stops its children before the parent completes its own stop sequence, but it does not guarantee the relative ordering of Terminated delivery versus the completion of ActorSystem.terminate().
Unresolved behavior
When ActorSystem.terminate() is called, the guardian and its supervision tree begin shutting down. A watched child that stops as a consequence of parent termination may deliver Terminated to its watcher either before or after the termination stage completes. This ordering is version-sensitive and not a documented guarantee, making it unsafe to rely on Terminated arrival for resource cleanup that must happen before the system is considered fully stopped.
Goal
Determine whether a configuration option, supervision strategy, or explicit coordination pattern exists that ensures Terminated for watched children is processed before ActorSystem.terminate() completes, without introducing custom shutdown barriers.
Specific questions:
- Is there a supported configuration or API that enforces
Terminateddelivery before termination stage completion? - If not, what is the recommended pattern for coordinating resource release that depends on child termination during system shutdown?