-
Notifications
You must be signed in to change notification settings - Fork 25
Spell.Peer.start_link required before Spell.connect #49
Description
While trying to get Spell working with an existing Crossbar setup, I continuously ran into errors with Spell.connect/2 exiting because of a no process error:
iex(1)> Spell.connect("ws://localhost:8080/ws/", realm: "realm1")
** (exit) exited in: GenServer.call(Spell.Peer.Supervisor, {:start_child, [%{owner: #PID<0.149.0>, realm: "realm1", retries: 5, retry_interval: 1000, role: %{features: %{callee: %{}, caller: %{}, publisher: %{}, subscriber: %{}}, options: [{Spell.Role.Session, [realm: "realm1"]}, {Spell.Role.Publisher, []}, {Spell.Role.Subscriber, []}, {Spell.Role.Caller, []}, {Spell.Role.Callee, []}]}, serializer: %{module: Spell.Serializer.JSON, options: []}, transport: %{module: Spell.Transport.WebSocket, options: [host: "localhost", port: 8080, path: "/ws/"]}}]}, :infinity)
** (EXIT) no process
(elixir) lib/gen_server.ex:596: GenServer.call/3
lib/spell.ex:152: Spell.init_peer/2I'm fairly new with Elixir, and so I searched around the internet with this rather-unhelpful stacktrace trying to find a solution. Finally, after about 2 days of reading through the source, it turned out that the Peer Supervisor hadn't been started by the time init_peer/2 was being called.
Starting the Supervisor manually by calling Spell.Peer.start_link/0 solved the issue:
iex(1)> Spell.Peer.start_link
{:ok, #PID<0.152.0>}
iex(2)> Spell.connect("ws://localhost:8080/ws/", realm: "realm1")
13:44:25.928 [debug] Connecting to ws://localhost:8080/ws/...
...
{:ok, #PID<0.154.0>}
iex(3)> I couldn't find anything in the documentation that hinted towards this, which was rather frustrating.
Would it be possible to either ensure that the Peer Supervisor is running before Spell.connect attempts to initialize a Peer, or add the Spell.Peer.start_link requirement somewhere in the documentation?