Skip to content

Commit f23f7fa

Browse files
Complete close() of a lazy prepared statement that was never executed (#1764) (#1805)
When PREPARE fails with an indeterminate type error, PG falls back to a statement prepared on its first execution. Closing such a statement before any execution did nothing, so the returned future never completed. Complete the close and mark the statement closed, so that a later execution fails instead of preparing it. Assisted-by: Anthropic Claude (claude-opus-5-5) (cherry picked from commit 8db96a0) Signed-off-by: Sharang Gupta <sharang@sharanggupta.dev> Signed-off-by: Thomas Segismont <tsegismont@gmail.com> Co-authored-by: Sharang Gupta <sharang@sharanggupta.dev>
1 parent 78d6d63 commit f23f7fa

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

‎vertx-pg-client/src/test/java/io/vertx/tests/pgclient/PreparedStatementTestBase.java‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,17 @@ public void testInferDataTypeLazy42P18(TestContext ctx) {
587587
}));
588588
}
589589

590+
@Test
591+
public void testCloseLazyPreparedStatementNotExecuted42P18(TestContext ctx) {
592+
PgConnection.connect(vertx, options()).onComplete(ctx.asyncAssertSuccess(conn -> {
593+
conn
594+
.prepare("SELECT CONCAT('HELLO', $1)")
595+
.compose(PreparedStatement::close)
596+
.eventually(() -> conn.close())
597+
.onComplete(ctx.asyncAssertSuccess());
598+
}));
599+
}
600+
590601
@Test
591602
public void testInferDataTypeFailure42P18(TestContext ctx) {
592603
PgConnection.connect(vertx, options()).onComplete(ctx.asyncAssertSuccess(conn -> {

‎vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/PreparedStatementBase.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ protected void close(Promise<Void> promise) {
134134
promise.fail(ar.cause());
135135
}
136136
});
137+
} else {
138+
// Never executed, so never prepared: nothing to close, and it must not be prepared afterwards
139+
future = context.failedFuture("Prepared statement closed");
140+
promise.complete();
137141
}
138142
}
139143
@Override

0 commit comments

Comments
 (0)