Skip to content

Commit f2a0975

Browse files
authored
Retry lost connections (#990)
Fixes `DB::ConnectionLost` errors.
1 parent 0b9797b commit f2a0975

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/avram/database.cr

+12-9
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,18 @@ abstract class Avram::Database
187187
# once the block is finished
188188
private def with_connection(&)
189189
key = object_id
190-
connections[key] ||= db.checkout
191-
connection = connections[key]
192-
193-
begin
194-
yield connection
195-
ensure
196-
if !connection._avram_in_transaction?
197-
connection.release
198-
connections.delete(key)
190+
191+
db.retry do
192+
connections[key] ||= db.checkout
193+
connection = connections[key]
194+
195+
begin
196+
yield connection
197+
ensure
198+
if !connection._avram_in_transaction?
199+
connection.release
200+
connections.delete(key)
201+
end
199202
end
200203
end
201204
end

0 commit comments

Comments
 (0)