On Jan 6, 7:58 am, Roland Swingler <[email protected]> wrote:
> Hi,
>
> I'm occasionally getting Sequel::DatabaseError: Mysql::Error: Lost
> connection to MySQL server during query
> when running with sequel + sinatra + passenger 3.
>
> Reading around there seem to be two possibilities for this:
>
> * It is just a standard timeout for mysql
> * It is caused by the connection being used simultaneously.
>
> I can't see a "reconnect" option in the mysql adapter like in
> activerecord, despite 
> thishttp://code.google.com/p/ruby-sequel/issues/detail?id=26
> saying it is fixed in trunk, nor can I see the MYSQL_OPT_RECONNECT
> being used anywhere, so is it the case that sequel cannot currently
> set this option? If so, will you welcome a patch to support this?

No.  The implicit reconnection feature in the mysql driver is turned
off.  Sequel will detect disconnects and remove that connection from
the pool (raising a DatabaseDisconnectError), and new connections will
automatically be created as needed.

Implicit reconnection causes problems with caching prepared
statements, which is one of the reasons that Sequel turns it off.
Another reason is that implicit reconnection can cause the same
statement to be executed twice, leading to problems with non-
idempotent statements.

Note that you can certainly turn implicit reconnection on if you want
to:

  DB = Sequel.mysql(..., :after_connect=>proc{|c| c.reconnect = true})

> The other possibility is that this is caused by passenger spawning new
> workers or somesuch. The db connection is currently kept in a global
> DB constant, which is defined in the config.ru file - should I instead
> be connecting every time a request comes through (seems unlikely) or
> performing some voodoo to reset the connection when passenger spawns
> new workers somehow?

In terms of forking, as long as you disconnect all database
connections before forking, you should be OK.  If you are only getting
the disconnect because the connections aren't being used, have a cron
job use the connection to do a simple DB query often enough so that
you don't hit the timeout.

Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to