preload_app = true causing - ActiveModel::MissingAttributeError: missing attribute: some_attr

Eric Wong normalperson at yhbt.net
Sun Jan 20 08:04:31 UTC 2013


Avner Cohen <avner.cohen at fiverr.com> wrote:
> Greetings,
> 
> I'm getting this  - ActiveModel::MissingAttributeError: missing
> attribute: some_attr  - on a random basis under a unicorn server,
> running rails 3.2 and ruby 1.9.3
> As the case of the last poster in the following thread -
> https://github.com/rails/rails/issues/1906 -  I too am able to resolve
> this issue by settingpreload_app to false.
> 
> However, this is not the behaviour I want to have.
> 
> Any inputs on that, or data I can provide around this issue?

Did you try disconnecting in your before_fork hook and reconnecting
after_fork?

before_fork do |server, worker|
  # the following is highly recomended for Rails + "preload_app true"
  # as there's no need for the master process to hold a connection
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect!
end

after_fork do |server, worker|
  # the following is *required* for Rails + "preload_app true",
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection
end

Open database handles must not be carried across fork.


More information about the mongrel-unicorn mailing list