Make the FLAME.Pool
handle backend.init/1 errors
#67
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Even though the
FLAME.Backend
allows for thebackend.init/1
to return an error:@callback init(opts :: Keyword.t()) :: {:ok, state :: term()} | {:error, term()}
The
FLAME.Pool
would not handle it and get into an infinite restart loop. This behavior can be tested withFlameTest.Application.call
in the https://github.com/mentels/flame_test that uses a custom backend whichinit/1
returns{:error, just_fail}.
If the pool is configured with
min: 0
, after the call we will keep getting:While if the runners are started at the application start-up (e.g.:
min: 1
), the application will not start at all, reporting an error:This commit attempts to fix the error by:
MatchError
resulting from the{:ok, pid} = DynamicSupervisor.start_child(state.runner_sup, spec)
in thestart_child_runner/2
start_child_runner/2
DynamicSupervisor.start_child/2
orRunner.remote_boot/2
{:exit, reason}
was not catching the exit signal from theDynamicSupervisor.start_child/2
```elixir iex(1)> try do throw({:exit, :ha}) catch {:exit, :ha} -> :haha end :haha iex(2)> try do exit(:ha) catch {:exit, :ha} -> :haha end ** (exit) :ha iex:2: (file) iex(2)> ````handle_info/2
clause to handle the{:error, reason}
Task resultboot_runners/2
{:exit, reason}
clause would never match since the PoolGenServer
is not trapping exists and thus the tasks spawn withTask.async_stream/3
would never return{:exit, reason}
as mentioned in the https://hexdocs.pm/elixir/Task.html#async_stream/5I think that the
Runner.remote_boot/2
might have the same problem but I will stop here and see if this work lands anywhere - maybe I'm missing the point :)