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

Race condition when a producer is closing too soon #76

Closed
Fenntasy opened this issue Mar 13, 2019 · 3 comments
Closed

Race condition when a producer is closing too soon #76

Fenntasy opened this issue Mar 13, 2019 · 3 comments

Comments

@Fenntasy
Copy link

There's a weird behaviour when dealing with a producer that has too little elements to deal with:

** (exit) exited in: GenStage.close_stream(%{#Reference<0.212111494.3424387074.139905> => {:subscribed, #PID<0.672.0>, :transient, 500, 1000, 1000}, #Reference<0.212111494.3424387074.139907> => {:subscribed, #PID<0.674.0>, :transient, 500, 1000, 1000}, #Reference<0.212111494.3424387074.139908> => {:subscribed, #PID<0.675.0>, :transient, 500, 1000, 1000}})
         ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
     code: assert :ok = MyFlow.run()
     stacktrace:
       (gen_stage) lib/gen_stage/stream.ex:160: GenStage.Stream.close_stream/1
       (elixir) lib/stream.ex:1370: Stream.do_resource/5
       (elixir) lib/enum.ex:2979: Enum.reverse/1
       (elixir) lib/enum.ex:2611: Enum.to_list/1
       (flow) lib/flow.ex:1012: Flow.run/1
        my_flow_test.exs:46: (test)

Here is a gist that have minimal code for this bug: https://gist.github.com/Fenntasy/1e930da0f7b6c2055a660831d4406a96

You can toggle between lines 30 and 31 to provoke the error or to not have it occur.

When the list is only two element, the producer will send its :terminate event immediatly and the previous error will show up. Displaying something on the console (via IO.inspect) would also be enough to not have the error (presumably because it adds a little bit of time before the producer closes).

Am I doing something wrong or is it really a race condition?

@josevalim
Copy link
Member

Definitely a race condition. We were supposed to handle those scenarios but it seems we do not. Although it is a bug in GenStage and not Flow. :) No worries though, I will transfer it accordingly. Thank you!

@cblavier
Copy link

I'm still having the issue. Has it been fixed yet in genstage?

@josevalim
Copy link
Member

@cblavier this PR was closed with a reference to a commit. So yes, it has been fixed (although it also required changes to Flow).

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

3 participants