Kraigie / nostrum

Elixir Discord Library
https://kraigie.github.io/nostrum/
MIT License
588 stars 125 forks source link

exited in: :gen_server.call(Nostrum.ConsumerGroup, {:join_local, :consumers, #PID<0.431.0>}, :infinity) #607

Closed yujonglee closed 2 weeks ago

yujonglee commented 2 weeks ago

I got this error:

** (EXIT) exited in: :gen_server.call(Nostrum.ConsumerGroup, {:join_local, :consumers, #PID<0.431.0>}, :infinity)
        ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started

I have {:nostrum, "~> 0.9", runtime: false}, with included_applications: [:nostrum].

In application.ex, I conditionally start it.

def start(_type, _args) do
  children = discord() ++ [...]
end

defp discord() do
  if Application.get_env(:nostrum, :token), do: [DiscordBot], else: []
end

I think due to runtime=false, ConsumerGroup is not started. But I don't know how to fix it. Any thoughts on this? Thank you.

jchristgit commented 2 weeks ago

defp discord() do if Application.get_env(:nostrum, :token), do: [DiscordBot], else: [] end

Is DiscordBot your consumer?

You will want to start Nostrum.Application ahead of DiscordBot, because Nostrum.ConsumerGroup (and the rest of nostrum, currently at least) will be started under Nostrum's own supervisor. You probably want:

defp discord() do if Application.get_env(:nostrum, :token), do: [Nostrum.Application, DiscordBot], else: [] end

Let me know if this helps!

yujonglee commented 2 weeks ago

@jchristgit

Yes, DiscordBot is my consumer.

I tried this:

  defp discord() do
    if Application.get_env(:nostrum, :token) do
      [Nostrum.Application, DiscordBot]
    else
      []
    end
  end

Now error message changed to:

shutdown: failed to start child: Nostrum.Application
    ** (EXIT) shutdown: failed to start child: Nostrum.Shard.Supervisor
        ** (EXIT) exited in: :gen_statem.call(Nostrum.Api.Ratelimiter, {:queue, %{params: [], body: "", headers: [{"content-type", "application/json"}], method: :get, route: "/gateway/bot"}}, :infinity)
            ** (EXIT) exited in: :gen_server.call(:gun_conns_sup, {:start_child, [#PID<0.438.0>, ~c"discord.com", 443, %{retry: 0, connect_timeout: 5000, domain_lookup_timeout: 5000, tls_handshake_timeout: 5000, tls_opts: [verify: :verify_peer ...
jchristgit commented 2 weeks ago
        ** (EXIT) exited in: :gen_server.call(:gun_conns_sup, {:start_child,

That's probably going to be because gun isn't started. Maybe you can put :gun_app or :gun_sup in that supervisor as well. BUt I'm not sure it is supported that way. Alternatively you could list :gun as an explicit dependency.

yujonglee commented 2 weeks ago

list :gun as an explicit dependency.

It works! Thank you.