rails: Intermittent failure on test environment about missing constants
Hello guys,
We have 3 complete different applications which are raising strange exceptions on the test environment.
I’m assuming it’s a race condition but I’m not sure, still trying to figure out what’s happening.
On a rails 4.0.4 application we are randomly seeing this exception:
An error occurred in an after hook
ActionController::RoutingError: Object is not missing constant PeopleController!
occurred at ..../activesupport-4.0.4/lib/active_support/dependencies.rb:449:in `load_missing_constant'
Using ActiveSupport::Dependencies.log_activity = true
, as @rafaelfranca suggested, we see this on the test.log:
Started POST "/people" for 127.0.0.1 at 2014-05-13 09:37:32 -0300
Started POST "/people" for 127.0.0.1 at 2014-05-13 09:37:32 -0300
Dependencies: called load_missing_constant(Object, :PeopleController)
Dependencies: called load_missing_constant(Object, :PeopleController)
Dependencies: called require_or_load("..../app/controllers/people_controller", "PeopleController")
Dependencies: called require_or_load("..../app/controllers/people_controller", "PeopleController")
Dependencies: requiring ..../app/controllers/people_controller
Dependencies: called require_or_load("people_helper", nil)
Dependencies: requiring people_helper
Processing by PeopleController#create as JSON
We are seeing similar failures on rails 4.1 applications (circular dependency exception appears from time to time and we don’t have any circular dependency).
What I can tell is that when we make 2 requests at same endpoint, in this case, at people controller, something happens on active support and it mess with the autoloading.
We changed config.eager_load
to true on the test environment and the exceptions seems to be gone, we are running the same build again over and over again to be sure it won’t fail again.
I’m assuming that is something related to the capybara running the server in a different thread but since webrick responds only one request per time, it do not makes sense.
Is that excepted to happen when eager load is false on test environment?
What else can we do to isolate the exception and you guys have some info about it?
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 59 (57 by maintainers)
Commits related to this issue
- inject Rack::Lock if config.eager_load is false If code is not eager loaded constants are loaded on demand. Constant autoloading is not thread-safe, so if eager loading is not enabled multi-threading... — committed to trungpham/rails by fxn 10 years ago
- inject Rack::Lock if config.eager_load is false If code is not eager loaded constants are loaded on demand. Constant autoloading is not thread-safe, so if eager loading is not enabled multi-threading... — committed to rails/rails by fxn 10 years ago
@matthewd there is no need to change the default
eager_load
totrue
in test env., however if multiple concurrent app-accessing threads are at any point involved, theneager_load
must be set totrue
.I have no idea how capybara works, but if the “
driver
” thread is “sequential” to “web-app
” thread (whereby “sequential” I mean the “driver
” thread is never running concurrently with a “web-app
”, ie “driver
” always blocks when calling “web-app
”, as in: it doesapp.call
and then waits for a response) then development mode const-loading should work just fine.