On Thursday, October 9, 2014 4:27:54 PM UTC-7, binarypaladin wrote:
>
> We recently removed ActiveRecord from a Rails project in favor of Sequel 
> (thank goodness). However, I started noticing some intermittent errors in 
> our staging environment and am seeing this error in the logs with some 
> regularity:
>
> Sequel::DatabaseDisconnectError (PG::ConnectionBad: PQconsumeInput() ):
>
> We weren't seeing these in AR which leads me to believe it was either 
> silently retrying or something in the way Sequel's connection pool is 
> configured needs to change. I'm just not even sure where to begin since 
> I've never seen this error before.
>
> I'm not seeing this at all on our local development machines which, in all 
> honesty, are seeing MORE traffic. We have Sidekiq running in both instances 
> which I think might be exhausting the connections? I dunno though. Any 
> ideas would be appreciated.
>

By design Sequel does not automatically retry queries on connection errors, 
as it isn't safe to do in the general case.  You can't possibly know if the 
disconnect occurred before or after the query took effect.

You mentioned that you were using Passenger, so assuming you are preloading 
your application (the default in passenger I believe), you must call 
Database#disconnect after loading your application.  Otherwise, the 
connection used when loading the app will be shared by the workers, which 
can cause the disconnect errors you are seeing.  Note that the same type of 
issue affects ActiveRecord, but Passenger automatically disconnects the 
ActiveRecord connection, which is why you wouldn't see this when running 
ActiveRecord.  So that's the first thing I would check.

Assuming that that doesn't fix it, you can use the connection_validator 
extension to validate connections before use.  You can also use 
Database#transaction :retry_on => Sequel::DatabaseDisconnectError, to 
automatically retry transactions, but you must be sure the entire 
transaction block is idempotent when doing so.

Thanks,
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