Skip to content

Rails5, auto-loading, future, circular dependencyΒ #585

Open
@jrochkind

Description

@jrochkind

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.

Metadata

Metadata

Assignees

Labels

enhancementAdding features, adding tests, improving documentation.medium-priorityShould be done soon.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions