Skip to content

Commit 78f6316

Browse files
committed
Fix PreparedStatement to set a unique name
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.
1 parent afab31e commit 78f6316

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/main/scala/com/twitter/finagle/postgres/PostgresClientImpl.scala

+4-5
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class PostgresClientImpl(
155155
typeMap().flatMap { _ =>
156156
for {
157157
service <- factory()
158-
statement = new PreparedStatementImpl("", sql, service)
158+
statement = new PreparedStatementImpl(sql, service)
159159
result <- statement.select(params: _*)(f)
160160
} yield result
161161
}
@@ -168,7 +168,7 @@ class PostgresClientImpl(
168168
typeMap().flatMap { _ =>
169169
for {
170170
service <- factory()
171-
statement = new PreparedStatementImpl("", sql, service)
171+
statement = new PreparedStatementImpl(sql, service)
172172
OK(count) <- statement.exec(params: _*)
173173
} yield count
174174
}
@@ -212,11 +212,12 @@ class PostgresClientImpl(
212212

213213

214214
private[this] class PreparedStatementImpl(
215-
name: String,
216215
sql: String,
217216
service: Service[PgRequest, PgResponse]
218217
) extends PreparedStatement {
219218

219+
private[this] val name = s"fin-pg-$id-" + counter.incrementAndGet
220+
220221
def closeService = service.close()
221222

222223
private[this] def parse(params: Param[_]*): Future[Unit] = {
@@ -302,8 +303,6 @@ class PostgresClientImpl(
302303
}.ensure(service.close())
303304
}
304305
}
305-
306-
private[this] def genName() = s"fin-pg-$id-" + counter.incrementAndGet
307306
}
308307

309308

version.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version in ThisBuild := "0.12.0-SNAPSHOT"
1+
version in ThisBuild := "0.12.1-SNAPSHOT"

0 commit comments

Comments
 (0)