Re: psql not responding to SIGINT upon db reconnection

Поиск
Список
Период
Сортировка
От Tristan Partin
Тема Re: psql not responding to SIGINT upon db reconnection
Дата
Msg-id CX5IOLTR8MAD.1UUDEG0X673Z4@neon.tech
обсуждение исходный текст
Ответ на Re: psql not responding to SIGINT upon db reconnection  (Heikki Linnakangas <hlinnaka@iki.fi>)
Ответы Re: psql not responding to SIGINT upon db reconnection  (Heikki Linnakangas <hlinnaka@iki.fi>)
Список 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)



В списке pgsql-hackers по дате отправления:

Предыдущее
От: "Daniel Verite"
Дата:
Сообщение: Re: [ psql - review request ] review request for \d+ tablename, \d+ indexname indenting
Следующее
От: Peter Geoghegan
Дата:
Сообщение: Re: How to stop autovacuum silently