Not finding process in registry despite having the correct key

Hello! I am having players join a queue and then redirecting them to a game page once the queue hits 4 players. However, the liveview page is not able to find the process.

The GameController prints that it was added to the registry, the QueueStarter prints that it can find the GameController, but the GameLive is not able to find it. I am not sure how to debug it further.

This is the relevant part of my GameLive liveview page

defmodule Website45sV3Web.GameLive do
  use Website45sV3Web, :live_view
  alias Website45sV3Web.Presence
  alias Website45sV3.Game.GameController
  alias Website45sV3.Game.Card

  def mount(%{"id" => game_id}, _session, socket) do
    username = socket.assigns.current_user.username

    IO.puts("Looking for game with game_id: #{game_id}")
    IO.inspect(game_id, label: "game_id")

    case Registry.lookup(Website45sV3.Registry, game_id) do
      [{game_pid, _}] ->
        IO.puts("Found game with game_id: #{game_id}")

The IO.puts(“Found game with game_id: #{game_id}”) is not being printed here, and the other case is chosen instead.

A sample debugging output is:
From the game controller:

Registered a game with name: 684888C0EBB1 and players: asd, Imbo1, scotchTape, thirdPerson
pid: #PID<0.342.0>

So the game controller is being started successfully

From the QueueStarter (which starts the game controller)

Found process with game_name: 684888C0EBB1

So the game controller is being added to the registry

But the GameLive is not able to find the process even though the key is correct

[debug] MOUNT Website45sV3Web.GameLive
  Parameters: %{"id" => "684888C0EBB1"}
Looking for game with game_id: 684888C0EBB1
game_id: "684888C0EBB1"

I would be grateful for any help with this.

1 Like

It is not a race condition?

In iex, can you find it wth Registry.lookup(Website45sV3.Registry, game_id)?

1 Like

I had an unrelated error causing the GameController to terminate. Idk how I didn’t catch this, sorry. Thank you for the suggestion of using iex, it was very useful