Skip to content

Commit c616fe2

Browse files
Move server shutdown translation to abstract mysql
1053 is the server shutdown error code. We see these fairly often at GitHub when, for example, shutting down Vitess vtage processes for maintenance. Translating the error to `ConnectionFailed` allows us to treat these as retryable connection error, so we can reconnect and hit a new vtage process. This is all true regardless of whether the adapter is trilogy or mysql2 or whatever, so this commit moves the translation out into the abstract mysql adapter.
1 parent 808b052 commit c616fe2

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,7 @@ def sync_timezone_changes(raw_connection)
776776
ER_DB_CREATE_EXISTS = 1007
777777
ER_FILSORT_ABORT = 1028
778778
ER_DUP_ENTRY = 1062
779+
ER_SERVER_SHUTDOWN = 1053
779780
ER_NOT_NULL_VIOLATION = 1048
780781
ER_NO_REFERENCED_ROW = 1216
781782
ER_ROW_IS_REFERENCED = 1217
@@ -804,7 +805,7 @@ def translate_exception(exception, message:, sql:, binds:)
804805
else
805806
super
806807
end
807-
when ER_CONNECTION_KILLED, CR_SERVER_GONE_ERROR, CR_SERVER_LOST, ER_CLIENT_INTERACTION_TIMEOUT
808+
when ER_CONNECTION_KILLED, ER_SERVER_SHUTDOWN, CR_SERVER_GONE_ERROR, CR_SERVER_LOST, ER_CLIENT_INTERACTION_TIMEOUT
808809
ConnectionFailed.new(message, sql: sql, binds: binds, connection_pool: @pool)
809810
when ER_DB_CREATE_EXISTS
810811
DatabaseAlreadyExists.new(message, sql: sql, binds: binds, connection_pool: @pool)

activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class TrilogyAdapter < AbstractMysqlAdapter
1313
ER_BAD_DB_ERROR = 1049
1414
ER_DBACCESS_DENIED_ERROR = 1044
1515
ER_ACCESS_DENIED_ERROR = 1045
16-
ER_SERVER_SHUTDOWN = 1053
1716

1817
ADAPTER_NAME = "Trilogy"
1918

@@ -201,12 +200,6 @@ def translate_exception(exception, message:, sql:, binds:)
201200
if exception.is_a?(::Trilogy::TimeoutError) && !exception.error_code
202201
return ActiveRecord::AdapterTimeout.new(message, sql: sql, binds: binds, connection_pool: @pool)
203202
end
204-
error_code = exception.error_code if exception.respond_to?(:error_code)
205-
206-
case error_code
207-
when ER_SERVER_SHUTDOWN
208-
return ConnectionFailed.new(message, connection_pool: @pool)
209-
end
210203

211204
case exception
212205
when SocketError, IOError

0 commit comments

Comments
 (0)