Skip to content

Commit

Permalink
Retry lost connections (#990)
Browse files Browse the repository at this point in the history
Fixes `DB::ConnectionLost` errors.
  • Loading branch information
akadusei authored Dec 27, 2023
1 parent 0b9797b commit f2a0975
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/avram/database.cr
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,18 @@ abstract class Avram::Database
# once the block is finished
private def with_connection(&)
key = object_id
connections[key] ||= db.checkout
connection = connections[key]

begin
yield connection
ensure
if !connection._avram_in_transaction?
connection.release
connections.delete(key)

db.retry do
connections[key] ||= db.checkout
connection = connections[key]

begin
yield connection
ensure
if !connection._avram_in_transaction?
connection.release
connections.delete(key)
end
end
end
end
Expand Down

0 comments on commit f2a0975

Please sign in to comment.