On Monday, March 24, 2014 1:45:50 PM UTC-7, Lloyd Hughes wrote:
>
> Hi,
>
> I am currently running an API written in Grape using Puma. However,
> occasionally when I query the API I get the following error: "Mysql2::Error:
> MySQL server has gone away"
>
> If i refresh the page it works as expected. My database.yml file is:
>
> production: adapter: mysql2 database: test_db host: localhost user: user
> password: pass development: adapter: mysql2 database: test_db_dev host:
> localhost user: user password: pass
>
> What causes this issue and how can I fix it? I am connecting like so:
>
> config = YAML::load_file("config/database.yml")[ENV['RACK_ENV']]
> DB =
> Sequel.connect("#{config['adapter']}://#{config['host']}/#{config['database']}",
>
> user: "#{config['user']}", password: "#{config['password']}")
>
>
This is expected behavior. If a disconnect error is detected, the
connection pool removes the connection from the pool, and reraises the
error. The next time a connection is needed, a new connection is made.
If you want to avoid raising the error at all, you can either make sure the
mysql server doesn't go away (usually making sure the connection is used
more often than the idle timeout), or use the connection_validator
extension (which can transparently check connections for validity).
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.