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

Proper handling of exceptions in workers #148

Open
CGenie opened this issue Jun 2, 2022 · 0 comments
Open

Proper handling of exceptions in workers #148

CGenie opened this issue Jun 2, 2022 · 0 comments

Comments

@CGenie
Copy link

CGenie commented Jun 2, 2022

Hello,

It's not clear to me how to handle exceptions inside poolboy workers. I'm using Elixir, but I think this applies to Erlang as well.

My code looks more or less like this:

task = Task.async(fn ->
  :poolboy.transaction(:worker, fn pid -> 
    try do
      GenServer.call(pid, {:someWorkerFunction})
    catch
      e, r ->
        # reraise e, r
    end
  end
end)
Task.await(task)

Suppose the worker function throws an exception (i.e. the call with {:someWorkerFunction}). If I comment out reraise e, r as above, worker fails silently and my code continues to run as nothing happened.

However, when I uncomment that reraise e, r statement (or in fact just remove the try...catch block), the worker crashes in such a way that I'm not able to catch it (wrapping Task.await in try...after seems to do nothing).

How should I proceed to be able to recover from such crashes as I need to call some cleanup code? I know the docs say that try...after "provides only a soft guarantee", but I guess I'm bit of a noob to handle this properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant