general-CbIC/poolex

Restart worker when caller dies

Opened this issue · 1 comments

Sourced from Elixir forum: link

And I also found one more bug. Consider this scenario:
Caller gets a worker, sends a long-running job to the worker, then caller dies and Poolex just returns this worker to the idle queue. In this case the next caller, can receive this worker which is still executing the long-running job and this caller won’t be able to execute anything with this worker. So I have a feeling that it might make sense to just restart the worker when caller dies before releasing this worker

👋

https://hexdocs.pm/elixir/Process.html#link/1 might be useful to handle it somewhat automatically. The caller would link the worker on checkout and if the caller dies, so does the worker, unless it's trapping exits, which it shouldn't, unless it's also a pool. On checkin the https://hexdocs.pm/elixir/Process.html#unlink/1 would be called.

That was a bad idea.