Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r5r2w-00FSot-4y for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Nov 2023 17:29:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1r5r2u-00BKFC-H9 for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Nov 2023 17:29:52 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r5r2u-00BKF4-6T for pgsql-hackers@lists.postgresql.org; Wed, 22 Nov 2023 17:29:52 +0000 Received: from mail-ot1-x32a.google.com ([2607:f8b0:4864:20::32a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1r5r2r-007oWr-BE for pgsql-hackers@postgresql.org; Wed, 22 Nov 2023 17:29:51 +0000 Received: by mail-ot1-x32a.google.com with SMTP id 46e09a7af769-6cd0a8bc6dcso12804a34.2 for ; Wed, 22 Nov 2023 09:29:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=neon.tech; s=google; t=1700674186; x=1701278986; darn=postgresql.org; h=in-reply-to:references:mime-version:content-transfer-encoding:cc :from:to:subject:message-id:date:from:to:cc:subject:date:message-id :reply-to; bh=jLxBkvK6YqTgu6Gxeh5952MZZSrMrEMBbfKTNTgKj+Y=; b=N5hQnNGrkENfQUWb7fnOR7hAzGmvX47Ow90l8V2wzwihlWtEK4GOGEz0LJdPukHzAv Ljv6O/R4sgNtspWZE3KY/Om/ia5/0/oVdjw9jMLp/e9t5pkY7q+IlgvKSjfkBl7C/zjj UtklZdagTZh3STtHHPjBhRn3T6Peh+lndbBY4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700674186; x=1701278986; h=in-reply-to:references:mime-version:content-transfer-encoding:cc :from:to:subject:message-id:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jLxBkvK6YqTgu6Gxeh5952MZZSrMrEMBbfKTNTgKj+Y=; b=YPH79tRKDjM8aOCO+Pvpp6AWBSv1OLrCrMgQ2o7Gxfgz/fvJafjXrzxK2CkpoU9fuX qEyVgdJgbiHr4XsjfgPxPQYIOJvKBrdlSRzw/vWqSLuF6Wy99fZH8eb5OYBxTqJcjKcC dVtSc70OeRkTNNHEgMvOvcVYEhixO/FpapQb5xCr1CR0EQysK4GBWh5nzQBZvUxoVg0k OwppM4WOkFQyAbnYUgjGBRMjKp64rODCIGIiBgcxwjdhODpxAHN+uKOS7ZpmZ1cFyqLD BwZAjUp+MTPJp9UEpi0Niih3vxmDYYyrJz+8J5MJJoNm+OYf3UL7rXXK2+5sz5vpO7oG IGHw== X-Gm-Message-State: AOJu0YxT0JAUQhRpI9OWUpJW5chPuUu/ps5J7f7/watfJKGmKz1gDDYN dSeE+P7xg1/rZq11LNN5CxDDJg== X-Google-Smtp-Source: AGHT+IEw18n4JXfuqNTUWT0oVqcEkYl15VeFrmHs6mMt8QDdykp7bYysAQYo9wl+M/T7YEuBO/6AuA== X-Received: by 2002:a9d:6c92:0:b0:6d6:4633:a735 with SMTP id c18-20020a9d6c92000000b006d64633a735mr3453095otr.8.1700674186579; Wed, 22 Nov 2023 09:29:46 -0800 (PST) Received: from localhost (2603-8080-e400-3bb2-0000-0000-0000-1c05.res6.spectrum.com. [2603:8080:e400:3bb2::1c05]) by smtp.gmail.com with ESMTPSA id n24-20020a9d64d8000000b006d7e1d3dedasm14022otl.32.2023.11.22.09.29.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Nov 2023 09:29:45 -0800 (PST) Content-Type: text/plain; charset=UTF-8; format=Flowed Date: Wed, 22 Nov 2023 11:29:42 -0600 Message-Id: Subject: Re: psql not responding to SIGINT upon db reconnection To: "Heikki Linnakangas" From: "Tristan Partin" Cc: "Tom Lane" , , "Shlok Kyal" Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 X-Mailer: aerc 0.16.0-68-g9b3e3d1b8803 References: <1588058.1690220636@sss.pgh.pa.us> <5e28b89f-0033-4e42-8184-b71b731c1aa2@iki.fi> In-Reply-To: <5e28b89f-0033-4e42-8184-b71b731c1aa2@iki.fi> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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= =20 > is established or cancelled. If I add a wait (select, poll, etc.), then I can't control-C during the=20 blocking call, so it doesn't really solve the problem. On Linux, we have=20 signalfds which seem like the perfect solution to this problem, "wait on=20 the pq socket or SIGINT." But that doesn't translate well to other=20 operating systems :(. > tristan957=3D> \c > NOTICE: Welcome to Neon! > Authenticate by visiting: > https://console.neon.tech/psql_session/XXXX >=20 >=20 > ^CTerminated You can see here that I can't terminate the command. Where you see=20 "Terminated" is me running `kill $(pgrep psql)` in another terminal. > Shouldn't we also clear CancelRequested after we have cancelled the=20 > attempt? Otherwise, any subsequent attempts will immediately fail too. After switching to cancel_pressed, I don't think so. See this bit of=20 code in the psql main loop: > /* main loop to get queries and execute them */ > while (successResult =3D=3D 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 =3D EXIT_USER; > break; > } >=20 > cancel_pressed =3D false; > } > Should we use 'cancel_pressed' here rather than CancelRequested? To be=20 > honest, I don't understand the difference, so that's a genuine question.= =20 > There was an attempt at unifying them in the past but it was reverted in= =20 > commit 5d43c3c54d. The more I look at this, the more I don't understand... I need to look=20 at this harder, but wanted to get this email out. Switched to=20 cancel_pressed though. Thanks for pointing it out. Going to wait to send=20 a v2 while more discussion occurs. --=20 Tristan Partin Neon (https://neon.tech)