AlanMcCann

AlanMcCann

Supervisor.start_child error :undef?

I’m having trouble getting Supervisor.start_child to work and I get the following error when running these commands (the supervisor is started automatically. Any help is appreciated. I’m likely missing something simple.

import Supervisor.Spec
sup_pid = sup_pid = Process.whereis(App.SessionSupervisor)
Supervisor.start_child(sup_pid,["a"])

{:error,
   {:EXIT,
    {:undef,
      [{App.Session, :start_link, [["a"]], []},
      {:supervisor, :do_start_child_i, 3, [file: 'supervisor.erl', line: 374]},
      {:supervisor, :handle_call, 3, [file: 'supervisor.erl', line: 399]},
      {:gen_server, :try_handle_call, 4, [file: 'gen_server.erl', line: 629]},
      {:gen_server, :handle_msg, 5, [file: 'gen_server.erl', line: 661]},
      {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 240]}]}}}

session_supervisor.ex

defmodule App.SessionSupervisor do
  use Supervisor

  def start_link do
    Supervisor.start_link(__MODULE__, :ok, name: App.SessionSupervisor)
  end

  def init(:ok) do
    children = [worker(App.Session, [], restart: :transient)]
    worker(App.Session, [], restart: :transient)

    supervise(children, strategy: :simple_one_for_one)
  end
end

session.ex

defmodule App.Session do

  use GenServer

  @doc """
  Starts a new session.
  """
  def start_link(uuid, opts \\ []) do
    GenServer.start_link(__MODULE__, %{uuid: uuid})
  end

… rest of the code.

Most Liked

scouten

scouten

Hi Alan, bumped into this just a few hours ago myself. The docs on this are terrible at telling you what you should provide. (Thankfully, that is a rarity!)

In my case, I had printed a start_link/1 function, but I needed to provide a start_link/2 function. Took me a while to get that right.

In your code, in see three different models name prefixes: App, Jaeger, and Jeager. Perhaps this is as simple as a typo?

AlanMcCann

AlanMcCann

Fix found - formatting the params for start_link as

["uuid", []]

vs

"uuid", []

allows it to properly started a linked child process

>iex -S mix
Erlang/OTP 18 [erts-7.3] [source-d2a6d81] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]

Interactive Elixir (1.3.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> sup_pid = Process.whereis(App.SessionSupervisor)
#PID<0.304.0>
iex(2)> Supervisor.count_children(sup_pid)
%{active: 0, specs: 1, supervisors: 0, workers: 0}
iex(3)> {:ok, pid} = Supervisor.start_child(sup_pid, ["uuid", []])
{:ok, #PID<0.311.0>}
iex(4)> Supervisor.count_children(sup_pid)
%{active: 1, specs: 1, supervisors: 0, workers: 1}

Thanks @NobbZ and @scouten for offering good pointers.

Where Next?

Popular in Questions Top

New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
dotdotdotPaul
Okay, I’m having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I’m sure I’...
New

Other popular topics Top

skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 53690 245
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
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
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New

We're in Beta

About us Mission Statement