david_ex

david_ex

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.20.2) 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.20.2) 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?

Showing Posts 1 to 2

OvermindDL1

OvermindDL1

I use :temporary for processes that should perform work then die, even if on failure, but should still be introspectable by the OTP system so I can see if something is running away.

I’m not sure what elixir is doing saying that if it is, but at least in Erlang a temporary child process is never restarted (not even when the supervisor restart strategy is rest_for_one or one_for_all and a sibling death causes the temporary process to be terminated). This is from:
https://erlang.org/doc/designprinciples/sup_princ.html

david_ex

david_ex OP

But if the process is :temporary you have no guarantee (out of the box, i.e. without monitoring, etc.) that the work gets done: the process could die before having completed the work. Do you by any chance have a practical example where you don’t care about that? Is it just for “nice to have”-level stuff (e.g. some tracking metric that is nice when available but not worth recomputing on failure)?

Regarding :temporary process restarts, my question is actually about “the other way around” than the one you mention above. Let’s say we have a supervisor S with a :one_for_all strategy. S has 2 children: a :permanent process P, and a :temporary process T.

It is clear to me killing process P will bring down T (and that T will not be restarted). However, it seems like killing T will never cause P to get restarted. But the Erlang docs state (from the same Supervisor Behaviour — Erlang System Documentation v29.0.2)

If a child process terminates, all other child processes are terminated

But that’s clearly not the case: in the example above, T is a child process that gets killed (and therefore terminates), yet all other child processes were NOT terminated since P remained alive.

I just wanted to verify I wasn’t missing something completely obvious. I’ve tried to clarify the (Elixir) docs with respect to this situation: clarify behavior of `:temporary` processes within supervisor strategies by davidsulc · Pull Request #7589 · elixir-lang/elixir · GitHub

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews