public inbox for [email protected]
help / color / mirror / Atom feedFrom: Heikki Linnakangas <[email protected]>
To: Jelte Fennema-Nio <[email protected]>
Cc: PostgreSQL Hackers <[email protected]>
Cc: Alvaro Herrera <[email protected]>
Cc: Jacob Champion <[email protected]>
Subject: Re: Don't use the deprecated and insecure PQcancel in our frontend tools anymore
Date: Tue, 7 Jul 2026 17:52:12 +0300
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
On 07/07/2026 10:54, Jelte Fennema-Nio wrote:
> On Tue Jul 7, 2026 at 12:12 AM CEST, Heikki Linnakangas wrote:
>> This relies on the signal to interrupt select(), but I'm afraid that's
>> not guaranteed on all platforms. Also, there's a race condition if the
>> signal arrives *just* before you call select(). That's what the "self-
>> pipe hack" is for, see comments at waiteventset.c.
>
> Ugh yes you're right. The comment above that block told me otherwise and
> I didn't question it. Attached is a new version that improves the
> comment and starts using the same 1 second poll on all platforms.
Yeah, I guess that works.. But It's a little unsatisfactory to have to
poll, where we didn't poll before. I started to go down the rabbit hole,
here are the options I can think of:
a) switch to pselect() where available, fall back to select() with
timeout. We don't currently use pselect() anywhere, so this needs a new
configure check.
b) switch to ppoll() where available, fall back to select() with
timeout. ppoll() is already used in pgbench, and is a better interface
in general. However, it's different from select(), so the fallback code
would differ more.
c) switch to ppoll() where available, fall back to poll() with timeout.
Use WaitForMultipleObjectsEx() on Windows (it has neither ppoll() nor
poll()). The fallback would look more similar to the main code path than
with b), but the Windows implementation would be even more different. We
could actually eliminate the polling in Windows too, if we added an
Event object for the cancellation too.
d) like c), but write a helper function to implement poll()/ppoll() on
Windows using WaitForMultipleObjectsEx(). Could be used in more places then.
d) seems like the nicest option in the long run, but takes a little
effort, and I don't have a Windows system to test on currently.
While poking around, I noticed that we actually already have a win32
implementation of select() using WaitForMultipleObjectsEx(), in
src/backend/port/win32/socket.c. But AFAICS it's not used anywhere.
Other prior art: In libpq we have PQsocketPoll(), which uses poll() or
select(), but it only operates on a single socket.
I wonder if we could bump up our minimum portability requirements, and
e.g. require ppoll() on all all non-Windows systems.
- Heikki
view thread (24+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: Re: Don't use the deprecated and insecure PQcancel in our frontend tools anymore
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox