On Tuesday, January 6, 2015 10:50:38 AM UTC-8, Lin Jen-Shin wrote:
>
> I just applied connection_validator and set connection_validation_timeout 
> to -1, 
> along with a middleware doing DB.synchronize around app.call as the 
> document 
> suggests, and report if there's a disconnection along with call stack. 
>
> The result was a bit surprising, that the validation with `SELECT NULL` 
> always 
> passed, and the disconnections happened on a specific query. Well, but 
> only on 
> production and only after a few seconds or minutes after the server 
> restarted. 
> After a burst of disconnections, everything went back to normal. 
>

If you are still getting disconnections with the connection validator 
extension and the timeout set to -1, that means that the disconnections are 
happen while the connection is currently checked out (not because it was 
idle, which is the usual use case for the connection validator).  I can 
think of only a few reasons this would happen:

1) The PostgreSQL server is disconnecting the client.
2) The client connection is getting disconnected manually, similar to what 
happens when you do fork/exit in ruby.
3) Multiple threads are attempting to use the connection
4) Streaming is being used and a second query is issued before the first 
result set is fully retrieved.

For 1), you can usually set up logging on the database server to check 
that, but I'm not sure if that's possible on Heroku.  For 2), you could 
probably add some logging around PG::Connection#finish, but if the 
disconnection is done by the garbage collector (finalizer), this won't 
detect that.  You'd actually have to patch the pg gem and add logging to 
the finalizer to detect that.  3) should not be possible in Sequel if you 
are using the default threaded connection pool, unless some code is keeping 
a reference to the connection and using it outside the block. 4) should 
only be an issue if you are using streaming, and based on your code example 
it seems unlikely (it would fail in the first query, not the second).

Hope this helps,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to