0
votes

I just installed the newrelic_rpm gem in my RefineryCMS Rails 3.2.3 application. I copied in the newrelic.yml config file as per the instructions. My app is being deployed with Heroku on the Cedar stack, so the instructions were pretty simple.

https://devcenter.heroku.com/articles/newrelic#cedar

However, running "rails server" on my development box gave me this error message:

/home/xxx/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in `retrieve_connection': ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished)

Setting the agent_enabled value to "false" in the newrelic.yml file allowed the server to start up again. Setting my license key and app name environment variables made no difference.

Interestingly, even though I couldn't get the app to start on my dev box, when I deployed it to Heroku, everything worked fine - and I am now getting new relic stats. Great!

My workaround has been to remove newrelic_rpm from the gemfile (which is what the install instructions say to do), and put it only into a :production group. Obviously, new relic is only useful in production, so it's no big deal.

group :production do
  ... other gems
  gem 'newrelic_rpm'
end

Anyone else ever experienced this, or know why it should be causing an ActiveRecord error (with no mention in the error trace of new relic at all)?

1

1 Answers

0
votes

The issue you were running into looks like a bug in the newrelic_rpm gem that was addressed with our (I work at New Relic) recent 3.6.4 release. I'd suggest that you try updating to 3.6.4 to see if the issue persists.

By way of explanation: we have something in the newrelic_rpm gem called an EnvironmentReport, which gathers information about the environment your application is executing in (Rails version, gem versions, DB adapter, Ruby version, etc) to display in the UI. In version 3.6.0 of the newrelic_rpm gem, we pushed the generation of the EnvironmentReport into a background thread. Because the EnvironmentReport potentially referenced the ActiveRecord::Base constant, generating it could trigger some ActiveRecord initialization code paths that are not thread-safe. If the EnvironmentReport happened to hit ActiveRecord::Base at just the wrong time, it could trigger errors like what you were seeing on the main thread.

We addressed this in 3.6.4 by moving the generation of the EnvironmentReport back onto the main thread.

Sorry for the headache, and please let us know if 3.6.4 doesn't solve your issue.

Edit - hmm, just noticed that you asked about this before 3.6.0 was released. I'd still suggest trying 3.6.4, since I suspect a similar race condition may have existed in older versions of the newrelic_rpm.