postrank-labs / goliath

Goliath is a non-blocking Ruby web server framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sequel postgres connection fails when server run as daemon

snitko opened this issue · comments

I've been using Sequel gem (http://sequel.jeremyevans.net/) with postgres adapter inside Goliath and I've noticed a very weird behavior.

If Goliath is run as a daemon, then it fails with Sequel::DatabaseDisconnectError: PG::ConnectionBad: PQconsumeInput() SSL connection has been closed unexpectedly whereas if it is run normally, this never happens.

This error also doesn't happen with sqlite, both in normal and daemonized modes.
Any hints as to why this might be happening?

Ok, so a good explanation of what's going on is here: thuehlinger/daemons#31

The question then becomes, where should I connect to the DB so that it happens AFTER the process is daemonized? Currently I do it in #initialize. If I connect to the DB in #response the problem goes away, but I don't want to be connecting to the DB upon the first request, it doesn't seem appropriate. I would like the connection to be established before a user hits the site.

I have a rather custom setup in my project which has its own config dir and file, I don't want to contaminate the file tree with more files and folders and confuse users. Is there a way I can somehow inject that piece of code next to the #initialize and #response methods? A hook up like #after_initialize in Rails, maybe?

You can pass a custom config via -c directive; check the internal plumbing.