I’d like to confirm my understanding of restart: :temporary
workers and their use cases as I was unable to find anything about this (whether in the docs, or the web).
Let’s say I have a supervisor Sup with 2 children:
- Temp which has a
:temporary
restart value (Supervisor — Elixir v1.16.0) Note that despite the chosen restart strategy, this process is intended to always be alive. - Server which has the default restart value (i.e.
:permanent
)
Per the docs, temporary processes are never restarted: if I kill Temp (e.g. in the Observer) it won’t get restarted. However, killing Temp doesn’t trigger Sup to kill and restart Server even though the strategy is :one_for_all
. The docs (Supervisor — Elixir v1.16.0) say that
if a child process terminates, all other child processes are terminated and then all child processes (including the terminated one) are restarted
Per the above, my expectation would be that although no temporary processes would get restarted, killing a temporary child process would still trigger the others to restart. Shouldn’t the docs instead say
if a (non-
:temporary
) process terminates, …
Or is this common knowledge/self-evident?
What’s the goal behind the above configuration? To implement the service/worker pattern discussed e.g. in The basic Erlang service ⇒ worker pattern – The Intellectual Wilderness where Sup would start only Server, after which Server would start Temp when initializing. If Temp dies, Server should too, and Sup should restart only Server which in turn will start Temp. (To be clear, although Server is the one triggering Temp to start, it does not supervise it: both Server and Temp are supervised by Sup.)
Since :temporary
processes within a supervision tree never get restarted, and don’t trigger sibling restarts on failure, am I correct in assuming that to achieve the above, I need to trap exits within Server and link Server to Temp?
For my own edification, are there use cases for :temporary
workers that aren’t linked or monitored? In other words, besides use cases similar to the above, when would you use a :temporary
restart value instead of :transient
?