From 1c2b46a0f991471b67af1bf41650f27f679ba08b Mon Sep 17 00:00:00 2001 From: "Brian J. Cardiff" Date: Fri, 21 Apr 2023 16:19:35 -0300 Subject: [PATCH] Add synchronize around checkout_some --- src/db/pool_prepared_statement.cr | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/db/pool_prepared_statement.cr b/src/db/pool_prepared_statement.cr index ebdecc5..cb598e2 100644 --- a/src/db/pool_prepared_statement.cr +++ b/src/db/pool_prepared_statement.cr @@ -35,7 +35,11 @@ module DB # the connection is registered in `@connections` private def build_statement : Statement clean_connections - conn, existing = @db.checkout_some(@connections) + + conn, existing = @mutex.synchronize do + @db.checkout_some(@connections) + end + begin stmt = conn.prepared.build(@query) rescue ex