fcabouat

fcabouat

ConsumerSupervisor failed to start child from :undef error

Hi,

I’m not able to create and test basic ConsumerSupervisor behavior.

I tried to follow the docs, but had a few issues. First one is that my child spec lacked “restart: :transient” (not present in the docs Printer example ConsumerSupervisor — gen_stage v1.3.2 : should I create an issue ?).

Here’s my code

defmodule BasicConsumerSupervisor do
  defmodule MyConsumerSupervisor do
    use ConsumerSupervisor

    def start_link(arg) do
      ConsumerSupervisor.start_link(__MODULE__, arg)
    end

    def init(_arg) do
      children = [%{id: MyConsumer, start: {MyConsumer, :start_link, []}, restart: :transient}]
      opts = [strategy: :one_for_one]
      ConsumerSupervisor.init(children, opts)
    end
  end

  defmodule MyConsumer do
    def start_link(event, truc) do
      Task.start_link(fn ->
        IO.inspect({self(), event, truc})
      end)
    end
  end
end

And Iex session with errors

iex(2)> {:ok, c} = BasicConsumerSupervisor.MyConsumerSupervisor.start_link([])
{:ok, #PID<0.323.0>}
iex(3)> {:ok, p} = 0..100 |> Enum.to_list |> GenStage.from_enumerable()               
{:ok, #PID<0.325.0>}
iex(4)> GenStage.sync_subscribe(c, to: p)                                             
{:ok, #Reference<0.1632678573.1983643649.222301>}
iex(5)> 
18:44:26.775 [error] ConsumerSupervisor failed to start child from: {#PID<0.325.0>, #Reference<0.1632678573.1983643649.222301>} with reason: {:undef, [{MyConsumer, :start_link, [0], []}, {ConsumerSupervisor, :start_child, 3, [file: 'lib/consumer_supervisor.ex', line: 564]}, {ConsumerSupervisor, :start_events, 6, [file: 'lib/consumer_supervisor.ex', line: 424]}, {ConsumerSupervisor, :handle_events, 3, [file: 'lib/consumer_supervisor.ex', line: 413]}, {GenStage, :consumer_dispatch, 6, [file: 'lib/gen_stage.ex', line: 2329]}, {:gen_server, :try_dispatch, 4, [file: 'gen_server.erl', line: 637]}, {:gen_server, :handle_msg, 6, [file: 'gen_server.erl', line: 711]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 249]}]}


18:44:26.783 [error] ConsumerSupervisor failed to start child from: {#PID<0.325.0>, #Reference<0.1632678573.1983643649.222301>} with reason: {:undef, [{MyConsumer, :start_link, [1], []}, {ConsumerSupervisor, :start_child, 3, [file: 'lib/consumer_supervisor.ex', line: 564]}, {ConsumerSupervisor, :start_events, 6, [file: 'lib/consumer_supervisor.ex', line: 424]}, {ConsumerSupervisor, :handle_events, 3, [file: 'lib/consumer_supervisor.ex', line: 413]}, {GenStage, :consumer_dispatch, 6, [file: 'lib/gen_stage.ex', line: 2329]}, {:gen_server, :try_dispatch, 4, [file: 'gen_server.erl', line: 637]}, {:gen_server, :handle_msg, 6, [file: 'gen_server.erl', line: 711]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 249]}]}


18:44:26.800 [error] ConsumerSupervisor failed to start child from: {#PID<0.325.0>, #Reference<0.1632678573.1983643649.222301>} with reason: {:undef, [{MyConsumer, :start_link, [2], []}, {ConsumerSupervisor, :start_child, 3, [file: 'lib/consumer_supervisor.ex', line: 564]}, {ConsumerSupervisor, :start_events, 6, [file: 'lib/consumer_supervisor.ex', line: 424]}, {ConsumerSupervisor, :handle_events, 3, [file: 'lib/consumer_supervisor.ex', line: 413]}, {GenStage, :consumer_dispatch, 6, [file: 'lib/gen_stage.ex', line: 2329]}, {:gen_server, :try_dispatch, 4, [file: 'gen_server.erl', line: 637]}, {:gen_server, :handle_msg, 6, [file: 'gen_server.erl', line: 711]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 249]}]}

Any ideas what could be wrong ?

cheers,

First 3 of 3 Posts Switch mode

NobbZ

NobbZ

There is no module named MyConsumer, you probably mean BasicConsumerSupervisor.MyConsumer.

fcabouat

fcabouat OP

You’re right, I fixed it. But I still get the same error though.

defmodule BasicConsumerSupervisor.MyConsumerSupervisor do
  use ConsumerSupervisor

  def start_link(arg) do
    ConsumerSupervisor.start_link(__MODULE__, arg)
  end

  def init(_arg) do
    children = [
      %{
        id: BasicConsumerSupervisor.MyConsumer,
        start: {BasicConsumerSupervisor.MyConsumer, :start_link, []},
        restart: :transient
      }
    ]

    opts = [strategy: :one_for_one]
    ConsumerSupervisor.init(children, opts)
  end
end

defmodule BasicConsumerSupervisor.MyConsumer do
  def start_link(event, truc) do
    Task.start_link(fn ->
      IO.inspect({self(), event, truc})
    end)
  end
end

{:ok, c} = BasicConsumerSupervisor.MyConsumerSupervisor.start_link([])
{:ok, p} = 0..10 |> Enum.to_list() |> GenStage.from_enumerable()
GenStage.sync_subscribe(c, to: p)
Process.sleep(:infinity)

=>

20:49:47.967 [error] ConsumerSupervisor failed to start child from: {#PID<0.145.0>, #Reference<0.3581977563.3345743873.173221>} with reason: {:undef, [{BasicConsumerSupervisor.MyConsumer, :start_link, [0], []}, {ConsumerSupervisor, :start_child, 3, [file: 'lib/consumer_supervisor.ex', line: 564]}, {ConsumerSupervisor, :start_events, 6, [file: 'lib/consumer_supervisor.ex', line: 424]}, {ConsumerSupervisor, :handle_events, 3, [file: 'lib/consumer_supervisor.ex', line: 413]}, {GenStage, :consumer_dispatch, 6, [file: 'lib/gen_stage.ex', line: 2329]}, {:gen_server, :try_dispatch, 4, [file: 'gen_server.erl', line: 637]}, {:gen_server, :handle_msg, 6, [file: 'gen_server.erl', line: 711]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 249]}]}                                                                                                                                                                                         


20:49:47.967 [error] ConsumerSupervisor failed to start child from: {#PID<0.145.0>, #Reference<0.3581977563.3345743873.173221>} with reason: {:undef, [{BasicConsumerSupervisor.MyConsumer, :start_link, [1], []}, {ConsumerSupervisor, :start_child, 3, [file: 'lib/consumer_supervisor.ex', line: 564]}, {ConsumerSupervisor, :start_events, 6, [file: 'lib/consumer_supervisor.ex', line: 424]}, {ConsumerSupervisor, :handle_events, 3, [file: 'lib/consumer_supervisor.ex', line: 413]}, {GenStage, :consumer_dispatch, 6, [file: 'lib/gen_stage.ex', line: 2329]}, {:gen_server, :try_dispatch, 4, [file: 'gen_server.erl', line: 637]}, {:gen_server, :handle_msg, 6, [file: 'gen_server.erl', line: 711]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 249]}]}                                                                                                                                                                                         


20:49:47.968 [error] ConsumerSupervisor failed to start child from: {#PID<0.145.0>, #Reference<0.3581977563.3345743873.173221>} with reason: {:undef, [{BasicConsumerSupervisor.MyConsumer, :start_link, [2], []}, {ConsumerSupervisor, :start_child, 3, [file: 'lib/consumer_supervisor.ex', line: 564]}, {ConsumerSupervisor, :start_events, 6, [file: 'lib/consumer_supervisor.ex', line: 424]}, {ConsumerSupervisor, :handle_events, 3, [file: 'lib/consumer_supervisor.ex', line: 413]}, {GenStage, :consumer_dispatch, 6, [file: 'lib/gen_stage.ex', line: 2329]}, {:gen_server, :try_dispatch, 4, [file: 'gen_server.erl', line: 637]}, {:gen_server, :handle_msg, 6, [file: 'gen_server.erl', line: 711]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 249]}]}   

fcabouat

fcabouat OP

Ok, I’m quite stupid : I propagated old errors into new code : took me a while before understanding the first error (ConsumerSupervisor needing restart: transient or restart: temporary), and then I had remaining errors regarding functions arity. Here this is the start_link of BasicConsumerSupervisor.MyConsumer, which was wrong : I had added a second parameter which was superfluous.

Isolating things properly (the working gen_stage/examples/consumer_supervisor.exs at main · elixir-lang/gen_stage · GitHub example helped a lot) with cold head and I could find it.

Thanx.

— All posts loaded —

Where Next?

Trending in Questions Top

jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
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
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement