Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On Heroku, Cedar, with Unicorn: Getting ActiveRecord::StatementInvalid: PGError: SSL SYSCALL error: EOF detected

Heroku support says this has to do with their version of libssl on shared databases, but we've encountered it on a project that's on a dedicated database, too.

Basically this error happens every so often (closer to just after a deploy) on every project we've moved to the new Cedar stack with Unicorn configured to 3 workers:

Error Message:

ActiveRecord::StatementInvalid: PGError: SSL SYSCALL error: EOF detected : SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum WHERE a.at

Where:
some_controller#index
[PROJECT_ROOT]/vendor/bundle/ruby/1.9.1/gems/activerecord-3.0.11/lib/active_record/connection_adapters/postgresql_adapter.rb, line 505

No answers from heroku yet besides maybe wait who knows how long for us to upgrade our shared database servers* and I haven't found anything on google.

They also suggested it has to do with unicorn's workers overlapping and that we should switch to Thin but the performance gain is well worth the occasional error(I think!). I'm hoping there's a way to configure Unicorn to prevent the overlap.

Has anyone encountered this, and if so, what have you done to resolve it? Thanks!

*not their actual words, just how I felt after their response.

like image 252
Joe Sak Avatar asked Dec 13 '11 22:12

Joe Sak


1 Answers

Heroku support suggested that I add this to my Unicorn config:

Append to your config/unicorn.rb:

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

I added it and we haven't seen a single PGError: SSL SYSCALL error all day.

like image 104
Joe Sak Avatar answered Oct 21 '22 12:10

Joe Sak