aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2019-07-16 20:58:41 +0100
committerGitHub <noreply@github.com>2019-07-16 20:58:41 +0100
commit64fa70a9d1ab3cea4a024a358e8a7ac891a98880 (patch)
treea3e3a8dff8c52143dff48ce88ab6c27361443b90 /activerecord/lib
parent8a9a96c7e88ee2c7c4c6fc717ad4a3e7c9a672f8 (diff)
parent080939c98724b039704ca8115ba610134d1edcff (diff)
downloadrails-64fa70a9d1ab3cea4a024a358e8a7ac891a98880.tar.gz
rails-64fa70a9d1ab3cea4a024a358e8a7ac891a98880.tar.bz2
rails-64fa70a9d1ab3cea4a024a358e8a7ac891a98880.zip
Merge pull request #36692 from kirs/mysql2-adapter-timeout
Raise specific exception on Mysql2::Error::TimeoutError
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb6
-rw-r--r--activerecord/lib/active_record/errors.rb4
2 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
index e9ae8d159e..405fecb603 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -619,7 +619,11 @@ module ActiveRecord
when ER_QUERY_INTERRUPTED
QueryCanceled.new(message, sql: sql, binds: binds)
else
- super
+ if exception.is_a?(Mysql2::Error::TimeoutError)
+ ActiveRecord::AdapterTimeout.new(message, sql: sql, binds: binds)
+ else
+ super
+ end
end
end
diff --git a/activerecord/lib/active_record/errors.rb b/activerecord/lib/active_record/errors.rb
index c8c06375a3..012ff8c46f 100644
--- a/activerecord/lib/active_record/errors.rb
+++ b/activerecord/lib/active_record/errors.rb
@@ -365,6 +365,10 @@ module ActiveRecord
class QueryCanceled < StatementInvalid
end
+ # AdapterTimeout will be raised when database clients times out while waiting from the server
+ class AdapterTimeout < StatementInvalid
+ end
+
# UnknownAttributeReference is raised when an unknown and potentially unsafe
# value is passed to a query method when allow_unsafe_raw_sql is set to
# :disabled. For example, passing a non column name value to a relation's