617837 (2) [Avatar] Offline
#1
I've been struggling for the past few hours to get version 3 of of the Pooly application working as described in the book. The problem I'm running into is that killing any of the PoolSupervisors in observer seems to also kill Pooly.Server and therefore it restarts all PoolSupervisors, PoolServers, WorkerSupervisors, and Workers. I thought it may be a problem with my implementation, but even just pulling the version 3 code straight from github exhibits the same behavior.

I thought the purpose of the Pooly.PoolsSupervisor, Pooly.PoolServer, and Pooly.PoolSupervisor was so that when one Pooly.PoolSupervisor crashes, only the processes in that tree are restarted?

this is the error that is thrown whenever you kill any Pooly.PoolSupervisor
18:11:37.692 [error] GenServer #PID<0.152.0> terminating
** (stop) killed
Last message: {:EXIT, #PID<0.146.0>, :killed}
State: {:state, {#PID<0.152.0>, Pooly.WorkerSupervisor}, :simple_one_for_one, {[SampleWorker], %{SampleWorker => {:child, :undefined, SampleWorker, {SampleWorker, :start_link, []}, :permanent, 5000, :worker, [SampleWorker]}}}, {:maps, %{#PID<0.155.0> => [[]], #PID<0.157.0> => [[]], #PID<0.158.0> => [[]]}}, 5, 5, [], 0, Pooly.WorkerSupervisor, [#PID<0.147.0>, {SampleWorker, :start_link, []}]}

18:11:37.694 [error] GenServer :Pool2Server terminating
** (stop) killed
Last message: {:EXIT, #PID<0.146.0>, :killed}
State: %Pooly.PoolServer.State{mfa: {SampleWorker, :start_link, []}, monitors: #Reference<0.343131796.730988551.184121>, name: "Pool2", pool_sup: #PID<0.146.0>, size: 3, worker_sup: #PID<0.152.0>, workers: [#PID<0.158.0>, #PID<0.157.0>, #PID<0.155.0>]}

18:11:37.694 [error] GenServer Pooly.Server terminating
** (MatchError) no match of right hand side value: {:error, {{:shutdown, {:failed_to_start_child, Pooly.PoolServer, {:already_started, #PID<0.147.0>}}}, {:child, :undefined, :Pool2Supervisor, {Pooly.PoolSupervisor, :start_link, [[name: "Pool2", mfa: {SampleWorker, :start_link, []}, size: 3]]}, :permanent, :infinity, :supervisor, [Pooly.PoolSupervisor]}}}
    (pooly) lib/pooly/server.ex:38: Pooly.Server.handle_info/2
    (stdlib) gen_server.erl:637: :gen_server.try_dispatch/4
    (stdlib) gen_server.erl:711: :gen_server.handle_msg/6
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: {:start_pool, [name: "Pool2", mfa: {SampleWorker, :start_link, []}, size: 3]}
State: [[name: "Pool1", mfa: {SampleWorker, :start_link, []}, size: 2], [name: "Pool2", mfa: {SampleWorker, :start_link, []}, size: 3], [name: "Pool3", mfa: {SampleWorker, :start_link, []}, size: 4]]


Is the version 3 github code not working as intended?
Benjamin Tan Wei Hao (86) [Avatar] Offline
#2
Hi! A reader posted a fix, and I've just merged the code into the repo. Could you try that please? Thanks!
617837 (2) [Avatar] Offline
#3
Thanks for the quick reply. That merge didn't fix the issue, but it did introduce a new one.

Setting the worker_opts to "restart: :temporary" made it so that workers don't restart when you kill them directly. Undoing this change fixes the issue.

The only other meaningful change I saw was in the Pooly.PoolServer handle_info({:EXIT ... function where "pool_sup" was changed to "worker_sup". That change definitely makes sense, but it doesn't appear to fix the issue I described above. Killing any of the PoolSupervisors still results in all PoolSupervisors being restarted.