مراية لـ
https://github.com/postalserver/postal.git
تم المزامنة 2025-11-30 21:32:30 +00:00
fix: retry mysql connections on message DB pool
هذا الالتزام موجود في:
@@ -12,9 +12,11 @@ module Postal
|
||||
end
|
||||
|
||||
def use
|
||||
connection = checkout
|
||||
retried = false
|
||||
do_not_checkin = false
|
||||
begin
|
||||
connection = checkout
|
||||
|
||||
yield connection
|
||||
rescue Mysql2::Error => e
|
||||
if e.message =~ /(lost connection|gone away|not connected)/i
|
||||
@@ -22,6 +24,12 @@ module Postal
|
||||
# we won't add it back in to the pool so that it'll reconnect
|
||||
# next time.
|
||||
do_not_checkin = true
|
||||
|
||||
# If we haven't retried yet, we'll retry the block once more.
|
||||
if retried == false
|
||||
retried = true
|
||||
retry
|
||||
end
|
||||
end
|
||||
|
||||
raise
|
||||
|
||||
@@ -41,5 +41,16 @@ describe Postal::MessageDB::ConnectionPool do
|
||||
end.to raise_error Mysql2::Error
|
||||
expect(pool.connections).to eq []
|
||||
end
|
||||
|
||||
it "retries the block once if there is a connection error" do
|
||||
clients_seen = []
|
||||
expect do
|
||||
pool.use do |client|
|
||||
clients_seen << client
|
||||
raise Mysql2::Error, "lost connection to server"
|
||||
end
|
||||
end.to raise_error Mysql2::Error
|
||||
expect(clients_seen.uniq.size).to eq 2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
المرجع في مشكلة جديدة
حظر مستخدم