Skip to content

Commit

Permalink
Move server shutdown translation to abstract mysql
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
composerinteralia committed Jan 25, 2024
1 parent 808b052 commit c616fe2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
Expand Up @@ -776,6 +776,7 @@ def sync_timezone_changes(raw_connection)
ER_DB_CREATE_EXISTS = 1007
ER_FILSORT_ABORT = 1028
ER_DUP_ENTRY = 1062
ER_SERVER_SHUTDOWN = 1053
ER_NOT_NULL_VIOLATION = 1048
ER_NO_REFERENCED_ROW = 1216
ER_ROW_IS_REFERENCED = 1217
Expand Down Expand Up @@ -804,7 +805,7 @@ def translate_exception(exception, message:, sql:, binds:)
else
super
end
when ER_CONNECTION_KILLED, CR_SERVER_GONE_ERROR, CR_SERVER_LOST, ER_CLIENT_INTERACTION_TIMEOUT
when ER_CONNECTION_KILLED, ER_SERVER_SHUTDOWN, CR_SERVER_GONE_ERROR, CR_SERVER_LOST, ER_CLIENT_INTERACTION_TIMEOUT
ConnectionFailed.new(message, sql: sql, binds: binds, connection_pool: @pool)
when ER_DB_CREATE_EXISTS
DatabaseAlreadyExists.new(message, sql: sql, binds: binds, connection_pool: @pool)
Expand Down
Expand Up @@ -13,7 +13,6 @@ class TrilogyAdapter < AbstractMysqlAdapter
ER_BAD_DB_ERROR = 1049
ER_DBACCESS_DENIED_ERROR = 1044
ER_ACCESS_DENIED_ERROR = 1045
ER_SERVER_SHUTDOWN = 1053

ADAPTER_NAME = "Trilogy"

Expand Down Expand Up @@ -201,12 +200,6 @@ def translate_exception(exception, message:, sql:, binds:)
if exception.is_a?(::Trilogy::TimeoutError) && !exception.error_code
return ActiveRecord::AdapterTimeout.new(message, sql: sql, binds: binds, connection_pool: @pool)
end
error_code = exception.error_code if exception.respond_to?(:error_code)

case error_code
when ER_SERVER_SHUTDOWN
return ConnectionFailed.new(message, connection_pool: @pool)
end

case exception
when SocketError, IOError
Expand Down

0 comments on commit c616fe2

Please sign in to comment.