Re: psql not responding to SIGINT upon db reconnection

From: "Tristan Partin" <tristan(at)neon(dot)tech>
To: "Heikki Linnakangas" <hlinnaka(at)iki(dot)fi>
Cc: "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: 2023-11-22 21:29:45
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed Nov 22, 2023 at 3:00 PM CST, Heikki Linnakangas wrote:
> On 22/11/2023 19:29, Tristan Partin wrote:
> > On Thu Nov 16, 2023 at 8:33 AM CST, Heikki Linnakangas wrote:
> >> On 06/11/2023 19:16, Tristan Partin wrote:
> >>>>> That sounds like a much better solution. Attached you will find a v4
> >>>>> that implements your suggestion. Please let me know if there is
> >>>>> something that I missed. I can confirm that the patch works.
> >>
> >> This patch is missing a select(). It will busy loop until the connection
> >> is established or cancelled.
> >
> > If I add a wait (select, poll, etc.), then I can't control-C during the
> > blocking call, so it doesn't really solve the problem.
> Hmm, they should return with EINTR on signal. At least on Linux; I'm not
> sure how portable that is. See signal(7) man page, section "Interruption
> of system calls and library functions by signal handlers". You could
> also use a timeout like 5 s to ensure that you wake up and notice that
> the signal was received eventually, even if it doesn't interrupt the
> blocking call.

Ha, you're right. I had this working yesterday, but convinced myself it
didn't. I had a do while loop wrapping the blocking call. Here is a v4,
which seems to pass the tests that were pointed out to be failing

Noticed that I copy-pasted pqSocketPoll() into the psql code. I think
this may be controversial. Not sure what the best solution to the issue
is. I will pay attention to the buildfarm animals when they pick this

Tristan Partin
Neon (

Attachment Content-Type Size
v4-0001-Allow-SIGINT-to-cancel-psql-database-reconnection.patch text/x-patch 4.8 KB

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2023-11-22 21:59:44 Re: common signal handler protection
Previous Message Bruce Momjian 2023-11-22 21:28:51 Re: [HACKERS] Changing references of password encryption to hashing