Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the FLAME.Pool handle backend.init/1 errors #67

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions lib/flame/pool.ex
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,10 @@ defmodule FLAME.Pool do
{:noreply, handle_runner_async_up(state, pid, ref)}
end

def handle_info({ref, {:error, reason}}, %Pool{} = state) when is_reference(ref) do
{:stop, reason, state}
end

def handle_info(:async_boot_continue, %Pool{} = state) do
{:noreply, async_boot_runner(%Pool{state | async_boot_timer: nil})}
end
Expand Down Expand Up @@ -652,7 +656,10 @@ defmodule FLAME.Pool do
{_runner, new_acc} = put_runner(acc, pid)
new_acc

{:exit, reason}, _acc ->
{:ok, {:error, reason}}, _acc ->
raise "failed to boot runner: #{inspect(reason)}"

{:ok, {:exit, reason}}, _acc ->
raise "failed to boot runner: #{inspect(reason)}"
end)
else
Expand Down Expand Up @@ -693,16 +700,19 @@ defmodule FLAME.Pool do
restart: :temporary
}

{:ok, pid} = DynamicSupervisor.start_child(state.runner_sup, spec)
with {:start, {:ok, pid}} <- {:start, DynamicSupervisor.start_child(state.runner_sup, spec)},
{:remote_boot, :ok} <- {:remote_boot, Runner.remote_boot(pid, state.base_sync_stream)} do
{:ok, pid}
else
{:start, {:error, reason}} ->
{:error, {:start_error, reason}}

try do
case Runner.remote_boot(pid, state.base_sync_stream) do
:ok -> {:ok, pid}
{:error, reason} -> {:error, reason}
end
catch
{:exit, reason} -> {:error, {:exit, reason}}
{:remote_boot, {:error, reason}} ->
{:error, {:remote_boot_error, reason}}
end
catch
:exit, reason ->
{:error, {:exit, reason}}
end

defp put_runner(%Pool{} = state, pid) when is_pid(pid) do
Expand Down