مراية لـ
https://github.com/postalserver/postal.git
تم المزامنة 2026-01-17 05:33:35 +00:00
fix: retry mysql connections on message DB pool
هذا الالتزام موجود في:
@@ -12,9 +12,11 @@ module Postal
|
|||||||
end
|
end
|
||||||
|
|
||||||
def use
|
def use
|
||||||
connection = checkout
|
retried = false
|
||||||
do_not_checkin = false
|
do_not_checkin = false
|
||||||
begin
|
begin
|
||||||
|
connection = checkout
|
||||||
|
|
||||||
yield connection
|
yield connection
|
||||||
rescue Mysql2::Error => e
|
rescue Mysql2::Error => e
|
||||||
if e.message =~ /(lost connection|gone away|not connected)/i
|
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
|
# we won't add it back in to the pool so that it'll reconnect
|
||||||
# next time.
|
# next time.
|
||||||
do_not_checkin = true
|
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
|
end
|
||||||
|
|
||||||
raise
|
raise
|
||||||
|
|||||||
@@ -41,5 +41,16 @@ describe Postal::MessageDB::ConnectionPool do
|
|||||||
end.to raise_error Mysql2::Error
|
end.to raise_error Mysql2::Error
|
||||||
expect(pool.connections).to eq []
|
expect(pool.connections).to eq []
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|||||||
المرجع في مشكلة جديدة
حظر مستخدم