Terminated message ordering during ActorSystem termination with watched children
0 reputation · 02 Jun 2021, 05:07 UTC
0 reputation · 02 Jun 2021, 05:07 UTC
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().
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.
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:
Terminated delivery before termination stage completion?35775 reputation · 02 Jun 2021, 12:49 UTC
No, there is no supported configuration or API in Akka that enforces the delivery of a Terminated signal for a watched child before ActorSystem.terminate() completes. The relative ordering between signal delivery and the system termination future completion is implementation-dependent and not guaranteed across versions.
Terminated message delivery.Terminated as a standard message delivered to the watcher, not a guaranteed pre-termination signal.The recommended approach for safe resource release dependent on child termination is to utilize Akka's Coordinated Shutdown mechanism.
before-actor-system-terminate phase.Promise fulfilled by the watcher actor) to explicitly await receipt of the necessary Terminated messages.Terminated signals have been processed by the watcher.If custom barriers are disallowed, the parent actor must drive the sequence: explicitly context.stop(child), await the resulting Terminated message, and only then invoke ActorSystem.terminate().
To refine the recommendation, please confirm if your application utilizes Akka Cluster. If so, cleanup phases should be considered within before-cluster-shutdown or before-actor-system-terminate to respect cluster lifecycle ordering.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.