Shutdown process
Closed this issue · 4 comments
Hello!
It seems like the library doesn't handle the shutdown process. The pool dies but the workers are still alive, which is very inconvenient. I took a quick look at poolboy and it uses a supervisor where the workers are placed to handle the shutdown process correctly. Do you have a plan to do something similar?
Thank you!
Hello!
Thank you for your issue!
This is a bug. Poolex
also uses supervisor to run workers under it. But it seems the current implementation missed an important terminate callback. I will fix it.
It will help a lot if you tell me how to reproduce this situation :)
Poolboy has a similar issue; it has an async shutdown. My mistake.
You can reproduce the issue very quickly. You can execute the following iex sequence:
iex(3)> {:ok, spid} = Poolex.start_link(pool_id: :agent_pool, worker_module: Agent, worker_
args: [fn -> 5 end], workers_count: 1)
{:ok, #PID<0.1336.0>}
iex(4)> Process.monitor(spid)
#Reference<0.4248042741.3728474113.42168>
iex(5)> Poolex.run!(:agent_pool, fn pid -> Process.monitor(IO.inspect(pid)) end)
#PID<0.1338.0>
#Reference<0.4248042741.3728474113.42180>
iex(6)> GenServer.stop(:agent_pool)
:ok
iex(7)> flush()
{:DOWN, #Reference<0.4248042741.3728474113.42168>, :process, #PID<0.1336.0>,
:normal}
{:DOWN, #Reference<0.4248042741.3728474113.42180>, :process, #PID<0.1338.0>,
:shutdown}
:ok
As you can see, the down message from poolex id is received before the worker one.
I hope it helps.
Hello, @alexcastano!
The bug should have been fixed in version 0.7.1.
Excellent work!! 👏🏻 👏🏻 ❤️