kgrvamsi

kgrvamsi

Dynamic supervisor terminate child issues

Hello Everyone

I’m working on a project which needs to use dynamic supervisor to support creating genserver based workers .

The code today can fork/spawn a worker and get attached to the parent dynamic supervisor but when i want to terminate i still see the process as part of the dynamic supervisor process.

Here is the code on the same

Dynamic supervisor code

defmodule Testing.WorkerSupervisor do
  @moduledoc """
      Worker Supervisor to support dynamic workers
  """
  use DynamicSupervisor
  require Logger

  def start_link(_) do
    Logger.debug("Starting the Worker Supervisor")
    DynamicSupervisor.start_link(__MODULE__, [], name: __MODULE__)
  end

  @impl true
  def init(_) do
    DynamicSupervisor.init(strategy: :one_for_one)
  end

  def start_task_worker(conn_id) do
    spec = {Testing.ConnectionWorker, %{conn_id: conn_id}}
    DynamicSupervisor.start_child(__MODULE__, spec)
  end

  def terminate_task_worker(pid) do
    Logger.info("Terminating the Worker")
    case DynamicSupervisor.terminate_child(__MODULE__, pid) do
      :ok ->
        Logger.info("Worker Terminated Successfully")

      {:error, _} ->
        Logger.info("PID not found")
    end
  end
end

The Processcheck worker who is part of the main supervisor i have this code

defmodule Testing.ConnectionWorker do
  @moduledoc false
  use GenServer, restart: :transient

state = %{
        conn_info: %{
              running: [%{
                       pid: "pid_id",
                       conn_name: "new worker"
               }]
         }
      }

Enum.each(diff, fn conn ->
            Enum.each(conn_info.running, fn run ->
              if conn == run.conn_name do
                IO.inspect(run.pid)
                Testing.WorkerSupervisor.terminate_task_worker(run.pid)
              end
            end)
          end)

When i see the process association with :observer.start i still see the worker attached to the Dynamic supervisor.

Am i doing the implementation wrong here?

First Post!

kokolegorille

kokolegorille

Hello welcome,

Try to change this…

use GenServer, restart: :transient

# to

use GenServer, restart: :temporary

… to test if it restarts or not (it should never restart). If not, it means on terminate_child, the worker does not stop with normal status, and so it is restarted because of transient.

BTW I usually stop GenServer from within, with a specific message, or under some conditions, but not from the supervisor itself, and not with terminate_child().

Where Next?

Popular in Questions Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New

We're in Beta

About us Mission Statement