dashbitco / flow

Computational parallel flows on top of GenStage

Home Page:https://hexdocs.pm/flow

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exceptions in Flow killing parent Oban process

cigrainger opened this issue · comments

When there's an exception in Flow, the parent process dies. This is not good in cases like Oban where it leads to zombie jobs. I note that this happens in IEx as well (IEx restarts). Minimal example:

defmodule WillDie do
  def dies(x) do
    raise "OH NO #{inspect(x)}"
  end
end

1..10 |> Flow.from_enumerable() |> Flow.map(&WillDie.dies/1) |> Enum.to_list()

I think there must be an obvious answer here to trap the exit and not crash the parent, but I don't know what it is.

You could add Process.flag(:trap_exit, true) before you call Flow.

However, Oban should be able to handle broken links too and not leave zombie jobs. Even and without trapping exits. For example, even doing spawn_link(fn -> raise "foo" end) should be fine. Ping @sorentwo.

That's what I couldn't remember! :trap_exit! Thank you. That's fixed the problem for us. I'm also interested to see what @sorentwo think.

I'm surprised to hear that you're getting zombie jobs from crashing processes. This property test exercises jobs with a multitude of failures, including linked processes crashing.

In situations like this, where nested processes crash, the producer traps exits and handles transitioning the job.

I can't replicate this in a minimal example so I guess we must be doing something wrong along the way? Happy to close this. Strange that Process.flag(:trap_exit, true) fixed it, though.