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

Avner Cohen avner.cohen at fiverr.com
Sun Jan 20 08:10:27 UTC 2013


Eric,
Thanks for the quick reply, and aplogies for not providing full info.
I do have these set up, here is my full configuration:

# -*- encoding : utf-8 -*-
worker_processes 4
working_directory "."
listen 3000
timeout 120

preload_app true

before_fork do |server, worker|
  defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
end


after_fork do |server, worker|
  defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
end

Best Regards,

Avner Cohen

On Sun, Jan 20, 2013 at 10:04 AM, Eric Wong <normalperson at yhbt.net> wrote:
> 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