If the database is hosted on a different box (and sometimes even if
it's on the same host), don't forget that there may be a stateful
firewall that is expiring state and denying packets (thus causing the
disconnect).
I've had to adapt a bunch of my long-running applications to catch the
MySQL disconnect and retry because of such things.
For one Sinatra app, I added a middleware class to wrap the app and
automagically restart it, something like:
class DBRetryWrapper
def initialize(app, maxtries=5)
@app = app
@maxtries = maxtries
end
def call(env)
tries = 0
begin
@app.call(env)
rescue Sequel::DatabaseDisconnectError, Mysql::Error => e
if /server has gone away/.match(e.message)
tries += 1
raise e if tries > @maxtries
retry
end
raise e
end
end
end
Aaron out.
--
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.