pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tristan Partin <tristan@neon.tech>
To: Heikki Linnakangas <hlinnaka@iki.fi>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-hackers@postgresql.org
Cc: Shlok Kyal <shlok.kyal.oss@gmail.com>
Subject: Re: psql not responding to SIGINT upon db reconnection
Date: Wed, 22 Nov 2023 11:29:42 -0600
Message-ID: <CX5IOLTR8MAD.1UUDEG0X673Z4@neon.tech> (raw)
In-Reply-To: <5e28b89f-0033-4e42-8184-b71b731c1aa2@iki.fi>
References: <CUAJJDVD8L61.2AH6VEEDMTXX3@gonk>
	<CUAKHCX5472I.SJP0AWQRYVFA@gonk>
	<CUAKIOVISECO.2S7MSQFOP1304@gonk>
	<1588058.1690220636@sss.pgh.pa.us>
	<CUAO24Z1Y72E.2069AD01EB4LO@gonk>
	<CANhcyEVBQWoPJK+C_h1CKyN3Wr2VKHuPx=bSB4PH2LuGdut4qg@mail.gmail.com>
	<CWRWDTTPP0WZ.2W75ZAVL5ND1M@neon.tech>
	<5e28b89f-0033-4e42-8184-b71b731c1aa2@iki.fi>

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)





view thread (43+ messages)  latest in thread

Message-ID: <CX5IOLTR8MAD.1UUDEG0X673Z4@neon.tech>
Permalink:  ../CX5IOLTR8MAD.1UUDEG0X673Z4@neon.tech/
Also on:    postgresql.org/message-id/CX5IOLTR8MAD.1UUDEG0X673Z4@neon.tech

 · 

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: pgsql-hackers@postgresql.org
  Cc: tristan@neon.tech, hlinnaka@iki.fi, tgl@sss.pgh.pa.us, shlok.kyal.oss@gmail.com
  Subject: Re: psql not responding to SIGINT upon db reconnection
  In-Reply-To: <CX5IOLTR8MAD.1UUDEG0X673Z4@neon.tech>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox