Hello,
I met a problem after commit 3a51306722.
While executing a SQL statement with psql, I can't interrupt it by pressing
ctrl+c.
For example:
postgres=# insert into test select generate_series(1,10000000);
^C^CINSERT 0 10000000
Press ctrl+c before finishing INSERT, and psql still continuing to INSERT.
I can confirm this unexpected change of behavior on this commit. This is
indeed e bug.
Is it the result expected?
Obviously not.
And I think maybe it is better to allow users to interrupt by pressing
ctrl+c.
Obviously yes.
The problem is that the cancellation stuff is cancelled too early after
sending an asynchronous request.
Attached a patch which attempts to fix this by moving the cancellation
cancelling request after processing results.
--
Fabien.
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index 028a357991..0482e57d45 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -1117,7 +1117,6 @@ SendQueryAndProcessResults(const char *query, double *pelapsed_msec, bool is_wat
INSTR_TIME_SET_CURRENT(before);
success = PQsendQuery(pset.db, query);
- ResetCancelConn();
if (!success)
{
@@ -1257,6 +1256,9 @@ SendQueryAndProcessResults(const char *query, double *pelapsed_msec, bool is_wat
if (!CheckConnection())
return -1;
+ /* all results are processed, nothing to cancel anymore */
+ ResetCancelConn();
+
return success ? 1 : -1;
}