Re: psql not responding to SIGINT upon db reconnection

From: "Tristan Partin" <tristan(at)neon(dot)tech>
To: "Robert Haas" <robertmhaas(at)gmail(dot)com>
Cc: "Heikki Linnakangas" <hlinnaka(at)iki(dot)fi>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, <pgsql-hackers(at)postgresql(dot)org>, "Shlok Kyal" <shlok(dot)kyal(dot)oss(at)gmail(dot)com>
Subject: Re: psql not responding to SIGINT upon db reconnection
Date: 2024-01-30 22:19:54
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri Jan 12, 2024 at 11:13 AM CST, Tristan Partin wrote:
> On Fri Jan 12, 2024 at 10:45 AM CST, Robert Haas wrote:
> > On Mon, Jan 8, 2024 at 1:03 AM Tristan Partin <tristan(at)neon(dot)tech> wrote:
> > > I think the way to go is to expose some variation of libpq's
> > > pqSocketPoll(), which I would be happy to put together a patch for.
> > > Making frontends, psql in this case, have to reimplement the polling
> > > logic doesn't strike me as fruitful, which is essentially what I have
> > > done.
> >
> > I encourage further exploration of this line of attack. I fear that if
> > I were to commit something like what you've posted up until now,
> > people would complain that that code was too ugly to live, and I'd
> > have a hard time telling them that they're wrong.
> Completely agree. Let me look into this. Perhaps I can get something up
> next week or the week after.

Not next week, but here is a respin. I've exposed pqSocketPoll as
PQsocketPoll and am just using that. You can see the diff is so much
smaller, which is great!

In order to fight the race condition, I am just using a 1 second timeout
instead of trying to integrate pselect or ppoll. We could add
a PQsocketPPoll() to support those use cases, but I am not sure how
available pselect and ppoll are. I guess on Windows we don't have
pselect. I don't think using the pipe trick that Heikki mentioned
earlier is suitable to expose via an API in libpq, but someone else
might have a different opinion.

Maybe this is good enough until someone complains? Most people would
probably just chalk any latency between keypress and cancellation as
network latency and not a hardcoded 1 second.

Thanks for your feedback Robert!

Tristan Partin
Neon (

Attachment Content-Type Size
v8-0001-Expose-PQsocketPoll-for-frontends.patch text/x-patch 3.6 KB
v8-0002-Allow-SIGINT-to-cancel-psql-database-reconnection.patch text/x-patch 2.8 KB

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Jelte Fennema-Nio 2024-01-30 22:42:50 Re: psql not responding to SIGINT upon db reconnection
Previous Message Andrew Dunstan 2024-01-30 22:18:49 Re: test fails on Windows with the newer Perl versions