Skip to content

Commit e9572ca

Browse files
fix connection drain
Signed-off-by: Aykut Bozkurt <aykut.bozkurt@snowflake.com>
1 parent f4a7307 commit e9572ca

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

pg_lake_engine/src/pgduck/client.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,27 @@ CancelRunningCommandOnConnection(PGconn *conn)
647647
return;
648648
}
649649

650+
/*
651+
* Try a non-blocking drain before resorting to cancel. When a query has
652+
* already completed (e.g. with an error) but the ereport(ERROR) unwound
653+
* the stack before libpq consumed ReadyForQuery, the connection still
654+
* appears ACTIVE. A single PQconsumeInput + drain is usually enough to
655+
* process the buffered ReadyForQuery and transition to IDLE, avoiding a
656+
* spurious cancel that can corrupt DuckDB session state.
657+
*/
658+
if (PQtransactionStatus(conn) == PQTRANS_ACTIVE &&
659+
PQconsumeInput(conn))
660+
{
661+
while (!PQisBusy(conn))
662+
{
663+
PGresult *res = PQgetResult(conn);
664+
665+
if (res == NULL)
666+
break;
667+
PQclear(res);
668+
}
669+
}
670+
650671
if (PQtransactionStatus(conn) == PQTRANS_ACTIVE)
651672
{
652673
/* a query is still running, cancel it */

pg_lake_spatial/tests/pytests/test_gdal.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,7 @@ def test_gdal_zip_gml(
203203
# Querying is currently not supported because WKB is converted by DuckDB
204204
# Error messages reflect different DuckDB spatial versions
205205
error = run_query("SELECT shape FROM test_gdal.fdw", user_conn, raise_error=False)
206-
assert (
207-
"Geometry type 10 not supported" in error
208-
or "'MULTICURVE' is not supported" in error
209-
or "Unsupported geometry type in WKB" in error
210-
)
206+
assert "Unsupported geometry type in WKB" in error
211207

212208
user_conn.rollback()
213209

0 commit comments

Comments
 (0)