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

Flow exiting with normal reason

TylerPachal opened this issue · comments

I am trying to supervise my Flow, and restart it if something goes wrong. In my supervisor init/1 I have something like this:

children = [
  worker(MyStreamer, [], restart: :transient)
]

MyStreamer has a start_link function that just creates the Flow then starts it:

def start_link(_) do
  flow = make_flow()
  Flow.start_link(flow)
end

The problem is that my supervisor is not restarting my flow when a runtime exception occurs, because the exit messages have :normal reasons like this:

{:EXIT, #PID<0.195.0>, :normal}

I was able to reproduce it by running this example in iex which raises a runtime error but has a normal exit reason:

Process.flag(:trap_exit, true)
flow = [3,2,1,0,-1,-2,-3] |> Flow.from_enumerable() |> Flow.map(&(10/&1))
Flow.start_link(flow)
flush()

I am expecting to see a non-normal exit reason like when doing this in iex:

Process.flag(:trap_exit, true)
spawn_link(fn -> 10/0 end)
flush()

I put together a small gist here. The code is simply:

## foo.exs

import IEx.Helpers

Process.flag(:trap_exit, true)

[3,2,1,0,-1,-2,-3]
|> Flow.from_enumerable()
|> Flow.map(&(10/&1)) # Generate a runtime error
|> Flow.start_link()

flush()

Thanks!