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 17:29:42
Message-ID: CX5IOLTR8MAD.1UUDEG0X673Z4@neon.tech
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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. On Linux, we have
signalfds which seem like the perfect solution to this problem, "wait on
the pq socket or SIGINT." But that doesn't translate well to other
operating systems :(.

> tristan957=> \c
> NOTICE: Welcome to Neon!
> Authenticate by visiting:
> https://console.neon.tech/psql_session/XXXX
>
>
> ^CTerminated

You can see here that I can't terminate the command. Where you see
"Terminated" is me running `kill $(pgrep psql)` in another terminal.

> Shouldn't we also clear CancelRequested after we have cancelled the
> attempt? Otherwise, any subsequent attempts will immediately fail too.

After switching to cancel_pressed, I don't think so. See this bit of
code in the psql main loop:

> /* main loop to get queries and execute them */
> while (successResult == EXIT_SUCCESS)
> {
> /*
> * Clean up after a previous Control-C
> */
> if (cancel_pressed)
> {
> if (!pset.cur_cmd_interactive)
> {
> /*
> * You get here if you stopped a script with Ctrl-C.
> */
> successResult = EXIT_USER;
> break;
> }
>
> cancel_pressed = false;
> }

> Should we use 'cancel_pressed' here rather than CancelRequested? To be
> honest, I don't understand the difference, so that's a genuine question.
> There was an attempt at unifying them in the past but it was reverted in
> commit 5d43c3c54d.

The more I look at this, the more I don't understand... I need to look
at this harder, but wanted to get this email out. Switched to
cancel_pressed though. Thanks for pointing it out. Going to wait to send
a v2 while more discussion occurs.

--
Tristan Partin
Neon (https://neon.tech)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2023-11-22 18:12:56 Re: How to stop autovacuum silently
Previous Message Daniel Verite 2023-11-22 16:24:43 Re: [ psql - review request ] review request for \d+ tablename, \d+ indexname indenting