Skip to content

Commit

Permalink
Fix PreparedStatement to set a unique name
Browse files Browse the repository at this point in the history
PostgreSQL prepared statements and portals are referenced by names,
and using a hardcoded empty string as name may cause race conditions
when executing queries in parallel.
  • Loading branch information
davoclavo committed Jun 11, 2019
1 parent afab31e commit 78f6316
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class PostgresClientImpl(
typeMap().flatMap { _ =>
for {
service <- factory()
statement = new PreparedStatementImpl("", sql, service)
statement = new PreparedStatementImpl(sql, service)
result <- statement.select(params: _*)(f)
} yield result
}
Expand All @@ -168,7 +168,7 @@ class PostgresClientImpl(
typeMap().flatMap { _ =>
for {
service <- factory()
statement = new PreparedStatementImpl("", sql, service)
statement = new PreparedStatementImpl(sql, service)
OK(count) <- statement.exec(params: _*)
} yield count
}
Expand Down Expand Up @@ -212,11 +212,12 @@ class PostgresClientImpl(


private[this] class PreparedStatementImpl(
name: String,
sql: String,
service: Service[PgRequest, PgResponse]
) extends PreparedStatement {

private[this] val name = s"fin-pg-$id-" + counter.incrementAndGet

def closeService = service.close()

private[this] def parse(params: Param[_]*): Future[Unit] = {
Expand Down Expand Up @@ -302,8 +303,6 @@ class PostgresClientImpl(
}.ensure(service.close())
}
}

private[this] def genName() = s"fin-pg-$id-" + counter.incrementAndGet
}


Expand Down
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version in ThisBuild := "0.12.0-SNAPSHOT"
version in ThisBuild := "0.12.1-SNAPSHOT"

0 comments on commit 78f6316

Please sign in to comment.