Skip to content

Commit

Permalink
fix: getConnection and conn.close are blocking calls
Browse files Browse the repository at this point in the history
  • Loading branch information
KaranAhlawat committed Jan 23, 2025
1 parent e5a20ad commit d6cb945
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ class Transactor[F[_]: Sync] private (

def transact[A](f: DbTx ?=> A): F[A] =
useRateLimitedConnection: cn =>
Sync[F].delay(connectionConfig(cn)) >>
Sync[F].delay(cn.setAutoCommit(false)) >>
Sync[F]
.delay {
connectionConfig(cn)
cn.setAutoCommit(false)
} >>
Sync[F]
.interruptible(f(using DbTx(cn, sqlLogger)))
.guaranteeCase {
Expand All @@ -61,14 +64,14 @@ class Transactor[F[_]: Sync] private (

private def acquireConnection: F[Connection] =
Sync[F]
.delay(dataSource.getConnection())
.blocking(dataSource.getConnection())
.adaptError(t => SqlException("Unable to acquire DB Connection", t))

private def releaseConnection(conn: Connection): F[Unit] =
if conn eq null then Sync[F].unit
else
Sync[F]
.delay(conn.close())
.blocking(conn.close())
.adaptError(t => SqlException("Unable to close DB connection", t))
end Transactor

Expand Down

0 comments on commit d6cb945

Please sign in to comment.