[erlang-questions] Questions about supervision
Oliver Korpilla
Oliver.Korpilla@REDACTED
Tue May 3 09:54:12 CEST 2016
Hello.
I ran into some unexpected results with supervision and transient workers and this gives me a few questions about process shutdown and resource cleanup.
I have a structure like this:
* main supervisor with several permanent children, one of them the (permanent) supervisor for transient children
* the supervisor for transient children creates processes grouped as follows:
- a "group" supervisor
- a worker maintaining a TCP connection (transient) linked with the group supervisor
- a worker running all the required procedures that determine one client linked with the group supervisor
- all these processes are registered under global under the same ID like this: {sup, <id>}, {conn, <id>}, {proc, <id>}
I read that transient children are only restarted on abnormal exit which is exactly what I want.
When trying to figure out how to best clean up the group of listed last, I ran into some snags, though...
I sometimes rely on the supervisor:which_children/1 call to find the IDs of all active groups. When inspecting all three layers of supervision I realized that processes are not cleaned up from the list of children like I expected.
Q1) So - lets say I have a transient child that exits with :normal, will its supervisor clean it out of its child lists eventually?
Furthermore, when reading through the documentation of gen_server and supervisor I came to this understanding:
- If shutdown is brutal_kill, no cleanup in the children can take place.
- If shutdown is infinity or <integer>, terminate in OTP worker children is called only if the child is trapping exits and the exit is not normal (like shutdown).
Q2) Is this understanding correct?
Q3) What is the pattern for properly and safely shutting down transient children? supervisor:terminate_child followed by supervisor:delete_child?
Q4) What is the pattern for keeping supervisors inner state clean so that they don't just accumulate transient children forever?
Thanks and best regards,
Oliver
More information about the erlang-questions
mailing list