Commit 3b4e7b315b598d10cf4c1a19d4a23b9da5ce12bf
1 parent
1647f46b
Exists in
master
and in
4 other branches
Added fix for "MySQL has gone away" errors with Resque workers.
Showing
1 changed file
with
17 additions
and
0 deletions
Show diff stats
| @@ -0,0 +1,17 @@ | @@ -0,0 +1,17 @@ | ||
| 1 | +module ActiveRecord::ConnectionAdapters | ||
| 2 | + class MysqlAdapter | ||
| 3 | + alias_method :execute_without_retry, :execute | ||
| 4 | + | ||
| 5 | + def execute(*args) | ||
| 6 | + execute_without_retry(*args) | ||
| 7 | + rescue ActiveRecord::StatementInvalid => e | ||
| 8 | + if e.message =~ /server has gone away/i | ||
| 9 | + warn "Server timed out, retrying" | ||
| 10 | + reconnect! | ||
| 11 | + retry | ||
| 12 | + else | ||
| 13 | + raise e | ||
| 14 | + end | ||
| 15 | + end | ||
| 16 | + end | ||
| 17 | +end |