Circular dependency detected while autoloading constant Clearance::SessionsController #276

Closed
localhots opened this Issue Mar 17, 2013 · 13 comments

Projects

None yet

2 participants

@localhots
Contributor

Rails 4.0.0.beta1
Clearance 1.0.0.rc6
Development environment

This bug is in all Clearance controllers, restarting the server helps for some time, but not for long.

@croaky
Member
croaky commented Mar 17, 2013

Thanks for the report, @magnolia-fan. Can you provide a backtrace and other steps to re-create this? I'm trying this now on those versions of Rails and Clearance and Ruby 2.0 but not able to re-create so far.

@localhots
Contributor

Sure, here is the full trace

RuntimeError (Circular dependency detected while autoloading constant Users::SessionsController):
vendor/gems/ruby/2.0.0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:460:in `load_missing_constant'
vendor/gems/ruby/2.0.0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:183:in `const_missing'
vendor/gems/ruby/2.0.0/gems/activesupport-4.0.0.beta1/lib/active_support/inflector/methods.rb:241:in `const_get'
vendor/gems/ruby/2.0.0/gems/activesupport-4.0.0.beta1/lib/active_support/inflector/methods.rb:241:in `block in constantize'
vendor/gems/ruby/2.0.0/gems/activesupport-4.0.0.beta1/lib/active_support/inflector/methods.rb:224:in `each'
vendor/gems/ruby/2.0.0/gems/activesupport-4.0.0.beta1/lib/active_support/inflector/methods.rb:224:in `inject'
vendor/gems/ruby/2.0.0/gems/activesupport-4.0.0.beta1/lib/active_support/inflector/methods.rb:224:in `constantize'
vendor/gems/ruby/2.0.0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:534:in `get'
vendor/gems/ruby/2.0.0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:565:in `constantize'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/routing/route_set.rb:74:in `controller_reference'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/routing/route_set.rb:64:in `controller'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/routing/route_set.rb:42:in `call'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/journey/router.rb:69:in `block in call'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/journey/router.rb:57:in `each'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/journey/router.rb:57:in `call'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/routing/route_set.rb:651:in `call'
vendor/gems/ruby/2.0.0/gems/newrelic_rpm-3.5.8.72/lib/new_relic/rack/agent_hooks.rb:14:in `call'
vendor/gems/ruby/2.0.0/gems/newrelic_rpm-3.5.8.72/lib/new_relic/rack/browser_monitoring.rb:12:in `call'
vendor/gems/ruby/2.0.0/gems/newrelic_rpm-3.5.8.72/lib/new_relic/rack/developer_mode.rb:24:in `call'
vendor/gems/ruby/2.0.0/bundler/gems/mongoid-124627a60020/lib/rack/mongoid/middleware/identity_map.rb:34:in `block in call'
vendor/gems/ruby/2.0.0/bundler/gems/mongoid-124627a60020/lib/mongoid/unit_of_work.rb:39:in `unit_of_work'
vendor/gems/ruby/2.0.0/bundler/gems/mongoid-124627a60020/lib/rack/mongoid/middleware/identity_map.rb:34:in `call'
vendor/gems/ruby/2.0.0/gems/rack-1.5.2/lib/rack/etag.rb:23:in `call'
vendor/gems/ruby/2.0.0/gems/rack-1.5.2/lib/rack/conditionalget.rb:25:in `call'
vendor/gems/ruby/2.0.0/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/flash.rb:241:in `call'
vendor/gems/ruby/2.0.0/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:225:in `context'
vendor/gems/ruby/2.0.0/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:220:in `call'
vendor/gems/ruby/2.0.0/gems/clearance-1.0.0.rc6/lib/clearance/rack_session.rb:10:in `call'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/cookies.rb:452:in `call'
vendor/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/query_cache.rb:36:in `call'
vendor/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/connection_adapters/abstract/connection_pool.rb:632:in `call'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
vendor/gems/ruby/2.0.0/gems/activesupport-4.0.0.beta1/lib/active_support/callbacks.rb:373:in `_run__404976410754846199__call__callbacks'
vendor/gems/ruby/2.0.0/gems/activesupport-4.0.0.beta1/lib/active_support/callbacks.rb:78:in `run_callbacks'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/reloader.rb:64:in `call'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
vendor/gems/ruby/2.0.0/gems/railties-4.0.0.beta1/lib/rails/rack/logger.rb:38:in `call_app'
vendor/gems/ruby/2.0.0/gems/railties-4.0.0.beta1/lib/rails/rack/logger.rb:23:in `call'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/request_id.rb:21:in `call'
vendor/gems/ruby/2.0.0/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
vendor/gems/ruby/2.0.0/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
vendor/gems/ruby/2.0.0/gems/activesupport-4.0.0.beta1/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
vendor/gems/ruby/2.0.0/gems/rack-1.5.2/lib/rack/lock.rb:17:in `call'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/static.rb:64:in `call'
vendor/gems/ruby/2.0.0/gems/railties-4.0.0.beta1/lib/rails/engine.rb:510:in `call'
vendor/gems/ruby/2.0.0/gems/railties-4.0.0.beta1/lib/rails/application.rb:96:in `call'
vendor/gems/ruby/2.0.0/gems/railties-4.0.0.beta1/lib/rails/railtie/configurable.rb:30:in `method_missing'
vendor/gems/ruby/2.0.0/gems/rack-1.5.2/lib/rack/lint.rb:49:in `_call'
vendor/gems/ruby/2.0.0/gems/rack-1.5.2/lib/rack/lint.rb:37:in `call'
vendor/gems/ruby/2.0.0/gems/rack-1.5.2/lib/rack/showexceptions.rb:24:in `call'
vendor/gems/ruby/2.0.0/gems/rack-1.5.2/lib/rack/commonlogger.rb:33:in `call'
vendor/gems/ruby/2.0.0/gems/rack-1.5.2/lib/rack/chunked.rb:43:in `call'
vendor/gems/ruby/2.0.0/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
vendor/gems/ruby/2.0.0/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:552:in `process_client'
vendor/gems/ruby/2.0.0/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:632:in `worker_loop'
vendor/gems/ruby/2.0.0/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:500:in `spawn_missing_workers'
vendor/gems/ruby/2.0.0/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:142:in `start'
vendor/gems/ruby/2.0.0/gems/unicorn-4.6.2/bin/unicorn:126:in `<top (required)>'
vendor/gems/ruby/2.0.0/bin/unicorn:23:in `load'
vendor/gems/ruby/2.0.0/bin/unicorn:23:in `<main>'
@croaky
Member
croaky commented Mar 17, 2013

Awesome, thanks. I'm wondering if unloadable changed in Rails 4 in some way. Will do some research.

http://apidock.com/rails/ActiveSupport/Dependencies/Loadable/unloadable

@croaky
Member
croaky commented Mar 17, 2013

It looks like in your backtrace that the circular dependency is with Users::SessionsController, not Clearance::SessionsController. Is Users::SessionsController a subclass of Clearance::SessionsController?

@localhots
Contributor

It's just a blank inheritance for /users/sign_in

module Users
  class SessionsController < Clearance::SessionsController
  end
end

Another trace, for /sign_in

RuntimeError (Circular dependency detected while autoloading constant Clearance::SessionsController):
vendor/gems/ruby/2.0.0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:460:in `load_missing_constant'
vendor/gems/ruby/2.0.0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:183:in `const_missing'
vendor/gems/ruby/2.0.0/gems/activesupport-4.0.0.beta1/lib/active_support/inflector/methods.rb:241:in `const_get'
vendor/gems/ruby/2.0.0/gems/activesupport-4.0.0.beta1/lib/active_support/inflector/methods.rb:241:in `block in constantize'
vendor/gems/ruby/2.0.0/gems/activesupport-4.0.0.beta1/lib/active_support/inflector/methods.rb:224:in `each'
vendor/gems/ruby/2.0.0/gems/activesupport-4.0.0.beta1/lib/active_support/inflector/methods.rb:224:in `inject'
vendor/gems/ruby/2.0.0/gems/activesupport-4.0.0.beta1/lib/active_support/inflector/methods.rb:224:in `constantize'
vendor/gems/ruby/2.0.0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:534:in `get'
vendor/gems/ruby/2.0.0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:565:in `constantize'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/routing/route_set.rb:74:in `controller_reference'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/routing/route_set.rb:64:in `controller'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/routing/route_set.rb:42:in `call'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/journey/router.rb:69:in `block in call'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/journey/router.rb:57:in `each'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/journey/router.rb:57:in `call'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/routing/route_set.rb:651:in `call'
vendor/gems/ruby/2.0.0/gems/newrelic_rpm-3.5.8.72/lib/new_relic/rack/agent_hooks.rb:14:in `call'
vendor/gems/ruby/2.0.0/gems/newrelic_rpm-3.5.8.72/lib/new_relic/rack/browser_monitoring.rb:12:in `call'
vendor/gems/ruby/2.0.0/gems/newrelic_rpm-3.5.8.72/lib/new_relic/rack/developer_mode.rb:24:in `call'
vendor/gems/ruby/2.0.0/bundler/gems/mongoid-124627a60020/lib/rack/mongoid/middleware/identity_map.rb:34:in `block in call'
vendor/gems/ruby/2.0.0/bundler/gems/mongoid-124627a60020/lib/mongoid/unit_of_work.rb:39:in `unit_of_work'
vendor/gems/ruby/2.0.0/bundler/gems/mongoid-124627a60020/lib/rack/mongoid/middleware/identity_map.rb:34:in `call'
vendor/gems/ruby/2.0.0/gems/rack-1.5.2/lib/rack/etag.rb:23:in `call'
vendor/gems/ruby/2.0.0/gems/rack-1.5.2/lib/rack/conditionalget.rb:25:in `call'
vendor/gems/ruby/2.0.0/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/flash.rb:241:in `call'
vendor/gems/ruby/2.0.0/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:225:in `context'
vendor/gems/ruby/2.0.0/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:220:in `call'
vendor/gems/ruby/2.0.0/gems/clearance-1.0.0.rc6/lib/clearance/rack_session.rb:10:in `call'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/cookies.rb:452:in `call'
vendor/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/query_cache.rb:36:in `call'
vendor/gems/ruby/2.0.0/gems/activerecord-4.0.0.beta1/lib/active_record/connection_adapters/abstract/connection_pool.rb:632:in `call'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
vendor/gems/ruby/2.0.0/gems/activesupport-4.0.0.beta1/lib/active_support/callbacks.rb:373:in `_run__404976410754846199__call__callbacks'
vendor/gems/ruby/2.0.0/gems/activesupport-4.0.0.beta1/lib/active_support/callbacks.rb:78:in `run_callbacks'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/reloader.rb:64:in `call'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
vendor/gems/ruby/2.0.0/gems/railties-4.0.0.beta1/lib/rails/rack/logger.rb:38:in `call_app'
vendor/gems/ruby/2.0.0/gems/railties-4.0.0.beta1/lib/rails/rack/logger.rb:23:in `call'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/request_id.rb:21:in `call'
vendor/gems/ruby/2.0.0/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
vendor/gems/ruby/2.0.0/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
vendor/gems/ruby/2.0.0/gems/activesupport-4.0.0.beta1/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
vendor/gems/ruby/2.0.0/gems/rack-1.5.2/lib/rack/lock.rb:17:in `call'
vendor/gems/ruby/2.0.0/gems/actionpack-4.0.0.beta1/lib/action_dispatch/middleware/static.rb:64:in `call'
vendor/gems/ruby/2.0.0/gems/railties-4.0.0.beta1/lib/rails/engine.rb:510:in `call'
vendor/gems/ruby/2.0.0/gems/railties-4.0.0.beta1/lib/rails/application.rb:96:in `call'
vendor/gems/ruby/2.0.0/gems/railties-4.0.0.beta1/lib/rails/railtie/configurable.rb:30:in `method_missing'
vendor/gems/ruby/2.0.0/gems/rack-1.5.2/lib/rack/lint.rb:49:in `_call'
vendor/gems/ruby/2.0.0/gems/rack-1.5.2/lib/rack/lint.rb:37:in `call'
vendor/gems/ruby/2.0.0/gems/rack-1.5.2/lib/rack/showexceptions.rb:24:in `call'
vendor/gems/ruby/2.0.0/gems/rack-1.5.2/lib/rack/commonlogger.rb:33:in `call'
vendor/gems/ruby/2.0.0/gems/rack-1.5.2/lib/rack/chunked.rb:43:in `call'
vendor/gems/ruby/2.0.0/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
vendor/gems/ruby/2.0.0/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:552:in `process_client'
vendor/gems/ruby/2.0.0/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:632:in `worker_loop'
vendor/gems/ruby/2.0.0/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:500:in `spawn_missing_workers'
vendor/gems/ruby/2.0.0/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:142:in `start'
vendor/gems/ruby/2.0.0/gems/unicorn-4.6.2/bin/unicorn:126:in `<top (required)>'
vendor/gems/ruby/2.0.0/bin/unicorn:23:in `load'
vendor/gems/ruby/2.0.0/bin/unicorn:23:in `<main>'
@localhots
Contributor

I'll try to provide a demo app for this issue.

@localhots
Contributor

Demo app: https://github.com/magnolia-fan/clearance_bug_demo

Simple steps to reproduce this issue:

  1. Start application in development environment
  2. Go to http://localhost:3000/sign_in
  3. Add a blank line to app/models/user.rb and save
  4. Refresh
@croaky
Member
croaky commented Mar 17, 2013

@magnolia-fan Thanks, editing the file and reloading was the key step I was missing on my local app. I'm now able to reproduce.

I also tried this with WEBrick and Unicorn to make sure it wasn't a Unicorn/Puma/pull issue. It happens with WEBrick as well.

I've pointed my Gemfile to my local Clearance and will by trying to isolate the issue further.

@croaky
Member
croaky commented Mar 17, 2013

Removing unloadable in the Clearance controllers fixes the issue. Not sure why yet.

@localhots
Contributor

Works for me too. Do these controllers really need to be unloadable?

@croaky
Member
croaky commented Mar 17, 2013

I'm guessing no. Will look more into it tonight and likely submit a PR with
an explanation of what changed.

On Sunday, March 17, 2013, Gregory Eremin wrote:

Works for me too. Do these controllers really need to be unloadable?


Reply to this email directly or view it on GitHubhttps://github.com/thoughtbot/clearance/issues/276#issuecomment-15029936
.

@croaky
Member
croaky commented Mar 18, 2013

Still not entirely sure why this is causing an issue now (Ruby 2.0 and/or Rails 4.0) and not earlier but opening #277 to address it.

@croaky croaky closed this Mar 18, 2013
@localhots
Contributor

Thanks!

@localhots localhots pushed a commit to localhots/clearance that referenced this issue Nov 11, 2013
@croaky croaky Remove `unloadable` from controllers
They are causing circular dependencies in Rails 4 + Ruby 2:

thoughtbot#276
6c22c6a
@yoon yoon pushed a commit to NUBIC/surveyor that referenced this issue Mar 24, 2014
@caboteria caboteria removed "unloadable" declarations
They were causing circular dependency errors in development when
classes changed and had to be recompiled.  Turns out they're no longer
needed for Rails 4:

   thoughtbot/clearance#276
   thoughtbot/clearance#277

In development if I change one of the classes it recompiles, even
without the "unloadable" declaration, and I no longer get circular
dependency errors.
d6dbce5
@fjyaniez fjyaniez pushed a commit to fjyaniez/ruby-saml-idp that referenced this issue Oct 15, 2014
Francis Yáñez Update idp_controller.rb
Removed unloadable (related to thoughtbot/clearance#276)
070f24b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment