File tree Expand file tree Collapse file tree
pg_lake_engine/src/pgduck
pg_lake_spatial/tests/pytests Expand file tree Collapse file tree Original file line number Diff line number Diff 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 */
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments