passenger: ActiveRecord::AdapterNotSpecified bug in latest update (6.0.5)

I performed an “apt update” on one of our Ubuntu 18.04 staging servers, and the update included Passenger version 6.0.5. Immediately after installing this update, our application started throwing the following error:

Error: The application encountered the following error: 'staging' database is not configured. Available: [] (ActiveRecord::AdapterNotSpecified)

I was able to track down the cause of the error to the following Passenger commit:

https://github.com/phusion/passenger/commit/3790eec8191dc4725f62f770f3039eec0d022fca#diff-696bdc7bb15daaa28a5f17914682f671

Manually reverting this commit to loader_shared_helpers.rb and restarting Nginx fixed the problem for us.

We are running a Ruby Cuba app, using ActiveRecord 5.2, with open source Passenger/Nginx, on Ubuntu 18.04.4 LTS. Ruby 2.5.1p57. Not sure if this affects Rails apps.

Happy to provide more info if needed.

Thanks

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 16
  • Comments: 19 (7 by maintainers)

Commits related to this issue

Most upvoted comments

This is happening in a Sinatra web app as well.

I think the issue is https://github.com/phusion/passenger/commit/3790eec8191dc4725f62f770f3039eec0d022fca#diff-696bdc7bb15daaa28a5f17914682f671 calls ActiveRecord::Base.establish_connection without any arguments and for non-rails project like Sinatra will cause error because the default ActiveRecord::Base.configurations is empty. 😩

I use the following config code to my Sinatra project as workaround:

 ActiveRecord::Base.configurations = { "production" =>  {"adapter"=>"sqlite3", "database"=>"db/production.sqlite3" } }

I have a legacy application on Sinatra that uses a custom DB connection with ActiveRecord::Base.establish_connection that was working till it was updated to 6.0.4. No longer works with 6.0.5.

i’m not really sure that calling ActiveRecord::Base.establish_connection is the right thing for passenger to do, personally. we have connection logic that is set up on app initialization which is being blasted away by this.

what’s the advantage of passenger doing this?

Yes, @ihower is correct. And the next version of Passenger should handle this case. Thanks to everyone who helped debug this issue.

Same here. I am building a docker image with the phusion/passenger-ruby26 and setting my environment variables for production stage. Had to update some scripts and rebuilt my image and i’m getting

Error: The application encountered the following error: 'production' database is not configured. Available: [] (ActiveRecord::AdapterNotSpecified)

I looked a lot to the updated code in search for some error in it. But is pretty much like the old code I had. Found this issue and it’s verry similar to the problem I have.

Full backtrace:

Rails backports are deprecated.
/usr/local/rvm/gems/ruby-2.6.6/gems/activesupport-4.2.11.1/lib/active_support/core_ext/object/duplicable.rb:111: warning: BigDecimal.new is deprecated; use BigDecimal() method instead.
Error: The application encountered the following error: 'production' database is not configured. Available: [] (ActiveRecord::AdapterNotSpecified)
    /usr/local/rvm/gems/ruby-2.6.6/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/connection_specification.rb:248:in `resolve_symbol_connection'
    /usr/local/rvm/gems/ruby-2.6.6/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/connection_specification.rb:211:in `resolve_connection'
    /usr/local/rvm/gems/ruby-2.6.6/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/connection_specification.rb:139:in `resolve'
    /usr/local/rvm/gems/ruby-2.6.6/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/connection_specification.rb:169:in `spec'
    /usr/local/rvm/gems/ruby-2.6.6/gems/activerecord-4.2.11.1/lib/active_record/connection_handling.rb:50:in `establish_connection'
    /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:320:in `before_handling_requests'
    /usr/share/passenger/helper-scripts/rack-preloader.rb:159:in `block in negotiate_spawn_command'
    /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:378:in `run_block_and_record_step_progress'
    /usr/share/passenger/helper-scripts/rack-preloader.rb:158:in `negotiate_spawn_command'
    /usr/share/passenger/helper-scripts/rack-preloader.rb:211:in `<module:App>'
    /usr/share/passenger/helper-scripts/rack-preloader.rb:30:in `<module:PhusionPassenger>'
    /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<main>'
[ E 2020-06-02 18:52:54.4440 34/T1h age/Cor/App/Implementation.cpp:221 ]: Could not spawn process for application /my/own/application: The application encountered the following error: 'production' database is not configured. Available: [] (ActiveRecord::AdapterNotSpecified)```

Checked the database.yml and it's correct

Hope to have a quick solution