Re: Don't use the deprecated and insecure PQcancel in our frontend tools anymore

From: Anthonin Bonnefoy <anthonin(dot)bonnefoy(at)datadoghq(dot)com>
To: Jelte Fennema-Nio <postgres(at)jeltef(dot)nl>
Cc: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, Jacob Champion <jacob(dot)champion(at)enterprisedb(dot)com>
Subject: Re: Don't use the deprecated and insecure PQcancel in our frontend tools anymore
Date: 2026-07-13 09:17:44
Message-ID: CAO6_XqoeNOzJstC0y46M3b4OtGbmScMHfH+WAng9ZsxmmxNbqw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

While testing the patch, it seems like there's a change of behavior
with psql and pager.

On master, with PAGER=less set, querying 'table pgbench_accounts;' and
doing a Ctrl-C would display a ":Cancel request sent" at the end of
the page.

With your patch, either nothing is reported, or the "Sending cancel
request" shows in the middle of the screen.

HEAD writes "Cancel request sent" after the cancel request was
successfully sent:
- if (PQcancel(cancel: cancelConn, errbuf, errbufsize: sizeof(errbuf)))
- {
- write_stderr(cancel_sent_msg);

With your patch, the message is now sent before the cancel request:
+ write_stderr(cancel_sent_msg);
+ if (!PQcancelBlocking(cancelConn: cc))
+ {

I think there's a race between less as it handles the SIGINT and
repaint the screen, and the 'write_stderr(cancel_sent_msg)'. If
write_stderr is processed between or during repaint, the message will
be visible, but possibly in the middle of the screen. If it's
processed before (probably what happens most of the time), then
repainting will erase the message.

On HEAD, this is indirectly avoided thanks to the cancel request
delay. By the time the cancel request is sent, less has finished
repainting.

Maybe it would be better to keep the old behavior and only write the
cancel_sent_msg after the cancel request was sent?

Regards,
Anthonin Bonnefoy

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Daniel Gustafsson 2026-07-13 09:21:56 Re: Clarify or fix SIGINT handling in data checksums launcher
Previous Message Dean Rasheed 2026-07-13 09:16:58 Re: Global temporary tables