Chex timeout with LiveView chess app called live_chess

I’m trying to resurrect this project

with LiveView 0.17 and I’ve managed to get it to the point where I make my move and it’s Chex engine’s turn but it times-out. Seems I had the exact same problem two years ago:

Anybody with experience with the Chex chess engine? I can say it fails in this chunk of code(“# Ask computer to move”):

    def handle_event(
          "square-clicked",
          %{"name" => to},
          %{assigns: %{selected_square: from, pid: pid}} = socket
        ) do
      case Chex.move(pid, from <> to) do
        {:error, _reason} ->
          {:noreply, assign(socket, selected_square: nil)}

        game ->
          dbg(pid) # `pid #=> #PID<0.3470.0>`
          # Ask computer to move
          GenServer.cast(pid, :engine_move)

          socket =
            socket
            |> assign(selected_square: nil)
            |> update_assigns_from_game(game)

          {:noreply, socket}
      end
    end

Full file.ex here: match_main_live.ex · GitHub

1 Like

Hello,

[..]
game ->
    dbg(pid) # `pid #=> #PID<0.3470.0>`
[..]

from https://elixir-lang.org/getting-started/debugging.html#dbg (dbg)

When code calling dbg is executed via iex, IEx will ask you to “stop” the code execution where the dbg call is. If you accept, you’ll be able to access all variables, as well as imports and aliases from the code, directly from IEx. This is called “prying”. While the pry session is running, the code execution stops, until continue or next are called. Remember you can always run iex in the context of a project with iex -S mix TASK.

dbg/2 has been introduced in elixir v1.14, so you must have added the dbg(pid) line recently, and maybe is not related with the timeout error you show above in elixir v1.11, but… could the present error (is it a timeout?) be related to that dbg(pid) line? Hth.

Removed the dbg() statement … no change.

Author of Chex and live_chess here. Glad to see there’s some interest in this as I haven’t touched live_chess since the Dockyard live_view competition. I made some major improvements to Chex since then but chose to abandon support for integrating with chess engines for now.

My guess without too much to go on is that Stockfish isn’t a great UCI citizen and given some invalid state, likes to segfault. This wasn’t a big deal for me at the time of the competition but I’d imagine you’re running into the same problem. I’d bet the Port that manages the Stockfish OS process is either down because Stockfish is crashing in some way.

If I was going to do live_chess again I would run Stockfish in the browser with Stockfish.js and let the browser send the computer move to the live view process using hooks.

I hope this helps. Let me know if there’s anything else I can do to help.

4 Likes