Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/mysql2/aurora.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ def initialize(opts)
reconnect!
end

def read_only_error?(msg)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits: Please write a comment with yard format 🙏

return false if msg.nil?
msg.include?('--read-only') || msg.include?('--super-read-only')
Comment on lines +23 to +24
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imho: I think this is better, but how about it?

!msg.nil? && ['--read-only', '--super-read-only'].any? { |term| msg.include?(term) }

end

# Execute query with reconnect
# @note [Override] with reconnect.
def query(*args)
Expand All @@ -29,7 +34,7 @@ def query(*args)
rescue Mysql2::Error => e
try_count += 1

if e.message&.include?('--read-only') && try_count <= @max_retry
if read_only_error?(e.message) && try_count <= @max_retry
retry_interval_seconds = [1.5 * (try_count - 1), 10].min

warn "[mysql2-aurora] Database is readonly. Retry after #{retry_interval_seconds}seconds"
Expand Down