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

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
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-11-26 08:44:50
Message-ID: 3ee16601-2953-409c-add8-571e3b5492b7@eisentraut.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Feedback on patch [PATCH v13 3/5] fe_utils: Simplify cancel logic in
wait_on_slots:

1) The value

struct timeval tv = {0, 1000000};

is actually somewhat incorrect if you think about it. It should be

struct timeval tv = {1, 0};

Apparently Windows and Linux accept the former in select(), but it fails
on macOS, and probably other BSD-derived systems.

Previously, this was only in the Windows code path, but now it's in the
fallback code for systems without pselect().

Actually, pselect() is in POSIX, so we should be able to require it
unconditionally on non-Windows system. Maybe it would be simpler and
more robust if select_loop() only had a Windows and a non-Windows code
path, instead of effectively three code paths as the patch is proposing
(pselect, Unix-no-pselect, Windows).

2) The new code loses the message "Cancel request sent" under some
circumstances. For example: Create three tables and lock them:

create table t1 (a int);
create table t2 (a int);
create table t3 (a int);

begin;
lock t1, t2, t3;
-- keep transaction open

Then in a separate terminal run a parallel vacuumdb with less slots than
tables:

vacuumdb -j2

Then press Ctrl+C as it hangs.

This aborts without printing a message.

If you lock only one table (so that there are more slots than tasks) and
press Ctrl+C, then the message is printed.

This should be fixed because the inconsistent behavior would inevitably
confuse users.

3) Small code simplification:

The

+ if (i < 0)
+ return -1;

is unnecessary, because if i is < 0 then it is necessarily -1, as a
result from pselect() or select(), and so the subsequent "return i" is
enough.

I have also looked at [PATCH v13 4/5] Move Windows pthread compatibility
functions to src/port. This makes a lot of sense to me, also seeing
that the corresponding header file pthread-win32.h is already in src/port/.

But actually shouldn't the header file be in src/include/port/ (or maybe
src/include/port/win32/)? Your 0005 patch needs to do some build system
surgery to find this file in its current nonstandard place.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Hayato Kuroda (Fujitsu) 2026-11-26 08:57:07 RE: Proposal: Conflict log history table for Logical Replication
Previous Message Alexandra Wang 2026-11-26 08:37:51 Re: Is there value in having optimizer stats for joins/foreignkeys?