ruby-concurrency / ruby-concurrency/concurrent-ruby

Rails5, auto-loading, future, circular dependency

Open
#585 49 comments 7 reactions 1 assignee View on GitHub

@pitr-ch is already working on this.

Since Jul 6, 2018.

enhancement medium-priority
Dominant language
Ruby
Stars
5.8k
Forks
420
Avg merge
20h 45m
Merged PRs (30d)
4

Description

My first time trying to use concurrent-ruby in Rails5 and with MRI 2.3. MRI 2.3.1. concurrent-ruby 1.0.2. Running into something very odd.

future = Concurrent::Future.execute { something_that_will_cause_rails_autoloading }
future.value

Hangs forever, never comes back. It's only by some weird debugging that I discovered it's "something_that_will_cause_autoloading" -- and I'm not certain of this, but I suspect it was Rails auto-loading behavior, How? Before calling future.value, I did a weird future.instance_variable_get('@executor').shutdown. After I do that, if I call future.value, it does return, but has failed -- and future.reason is #<RuntimeError: Circular dependency detected while autoloading constant BentoSearch::ResultItem> (which is one of my own classes)

So some thoughts:

  1. I am not sure why it's deciding there's a 'circular dependency', I can require 'bento_search/result_item' on it's own (not in a future) fine, with no warnings.
  2. I suspect I am doing something Rails doesn't like, perhaps you need to use some kind of eager loading if you are going to use concurrency in Rails 5?
  3. But even if I'm doing something wrong, why is the future hanging forever? What's actually going on? I'm not sure. I'd expect it to come back with an exception -- perhaps that "circular dependency" exception, why did I end up with that if I reached in to find the executor and shut it down myself, but a hang forever otherwise? It seems like concurrent-ruby is maybe doing something wrong.... maybe?

Wow, concurrency is confusing. Any thoughts.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.