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 1qO1h4-006cbY-NI for pgsql-hackers@arkaria.postgresql.org; Mon, 24 Jul 2023 19:58:11 +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 1qO1h2-00D5UB-Cp for pgsql-hackers@arkaria.postgresql.org; Mon, 24 Jul 2023 19:58:08 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qO1h1-00D5U2-Rl for pgsql-hackers@lists.postgresql.org; Mon, 24 Jul 2023 19:58:08 +0000 Received: from mail-ot1-x331.google.com ([2607:f8b0:4864:20::331]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qO1gu-001MvN-Nj for pgsql-hackers@postgresql.org; Mon, 24 Jul 2023 19:58:06 +0000 Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-6b9aadde448so4270011a34.0 for ; Mon, 24 Jul 2023 12:58:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=neon-tech.20221208.gappssmtp.com; s=20221208; t=1690228680; x=1690833480; h=in-reply-to:references:message-id:from:to:subject:cc:date :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=5kaV78s5DHPmusutVAdYe3z0fBGiGc/eofZtbDnKTN4=; b=Bgram3JsbgaGwqknULIUWhVK5711eXO3HUDbx0c5wkeAvjLQjxMY/N2LWg4TkOXPR/ qsmoRlMVZpPBHZwZff7Y0o0ojNgsEgVyPuqQMHe2wam3j1LyUkei1gbUX8HcOj63DdQ1 DdO9YLflcN4nbm74a2xIjLf5CNnahHHWNn1/eZVkoEBTRkXcUpxF4XVv/zJyjJlL/86v PcmB4mDSs6JG7tL+V46ZjZYM2oOnn8WvG5cG624eBugWWswAi7IjRDzqYaLm9wTp99B4 UkggABjMHqE8S4MsCtm5EJKKvfpTwg5YFGhF0NSlptFLsq0jzh4qtnjxQJDMAngx+StK hheg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690228680; x=1690833480; h=in-reply-to:references:message-id:from:to:subject:cc:date :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5kaV78s5DHPmusutVAdYe3z0fBGiGc/eofZtbDnKTN4=; b=ahDG4IQfq3/UCatKL0hgOB3i85gQwyqioeZ+RbzWycMx/AhLR45PLu57hWqb4twyr9 1R0lsYgT6KGUpkpiP1q5+ESo9ndgNKf+7FsrZ+NgQY+A4ORvExaF7HG6HqGjPBrvK4CO qrpVNGM4wBUPqFbHj2amkZv9IagI3n7kV73muZ7rs64rbMQjpHlNxxB2vcfKibN+ehvB lGOHY0Fo7OosXhjV6/VJN3acFsJALuN6FhoKL7tDOCPATlduG6YmJMHBkNUe/wmBNMTf fyrHBGcof6SX0aPNAj2yEByvTFinjDfQTzXzv9fFIiMKppJF3BplT4UjrZutEoZMKfGU UGKg== X-Gm-Message-State: ABy/qLbkIMegIGOpX+5oOBEZLg/f7sWsBDlmdjuQH/LRXtPrg5cLabEM Dj//m3SvIiqHNe1iLQg0dIOlKg== X-Google-Smtp-Source: APBJJlFJSD2SadeE8j1pSOwJnnyjs3PpJk96lOZkIbw9qDS+xUUzxP2jMaNU3PfGEi33xzvibhxZkA== X-Received: by 2002:a05:6871:452:b0:1ba:7ada:f29d with SMTP id e18-20020a056871045200b001ba7adaf29dmr13469914oag.50.1690228679865; Mon, 24 Jul 2023 12:57:59 -0700 (PDT) Received: from localhost ([2607:fb91:12af:534d:3996:e070:71ee:42fb]) by smtp.gmail.com with ESMTPSA id t67-20020a4a5446000000b00565ccb41ba5sm4729029ooa.3.2023.07.24.12.57.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 24 Jul 2023 12:57:59 -0700 (PDT) Content-Type: multipart/mixed; boundary=5ae4ba4c466da4b3a4842affd55f0cccceffa06d9b6773f36fe46ef17f9c Mime-Version: 1.0 Date: Mon, 24 Jul 2023 14:57:58 -0500 Cc: Subject: Re: psql not responding to SIGINT upon db reconnection To: "Tom Lane" From: "Tristan Partin" Message-Id: X-Mailer: aerc 0.15.2-105-g00bf476582f7 References: <1588058.1690220636@sss.pgh.pa.us> In-Reply-To: <1588058.1690220636@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --5ae4ba4c466da4b3a4842affd55f0cccceffa06d9b6773f36fe46ef17f9c Content-Type: multipart/alternative; boundary=f51172faf984fc3d2ce4319469b3aee7d23da8297bf93dd899b35131ef18 --f51172faf984fc3d2ce4319469b3aee7d23da8297bf93dd899b35131ef18 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Content-Type: text/plain; charset=UTF-8; format=Flowed On Mon Jul 24, 2023 at 12:43 PM CDT, Tom Lane wrote: > "Tristan Partin" writes: > > v3 is attached which fixes up some code comments I added which I hadn't= =20 > > attached to the commit already, sigh. > > I don't care for this patch at all. You're bypassing the pqsignal > abstraction layer that the rest of psql goes through, and the behavior > you're implementing isn't very nice. People do not expect ^C to > kill psql - it should just stop the \c attempt and leave you as you > were. > > Admittedly, getting PQconnectdbParams to return control on SIGINT > isn't too practical. But you could probably replace that with a loop > around PQconnectPoll and test for CancelRequested in the loop. That sounds like a much better solution. Attached you will find a v4=20 that implements your suggestion. Please let me know if there is=20 something that I missed. I can confirm that the patch works. $ ./build/src/bin/psql/psql -h pg.neon.tech NOTICE: Welcome to Neon! Authenticate by visiting: https://console.neon.tech/psql_session/xxx =09 =09 NOTICE: Connecting to database. psql (17devel, server 15.3) SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compres= sion: off) Type "help" for help. =09 tristan957=3D> \c NOTICE: Welcome to Neon! Authenticate by visiting: https://console.neon.tech/psql_session/yyy =09 =09 ^Cconnection to server at "pg.neon.tech" (3.18.6.96), port 5432 failed:=20 Previous connection kept tristan957=3D>=20 --=20 Tristan Partin Neon (https://neon.tech) --f51172faf984fc3d2ce4319469b3aee7d23da8297bf93dd899b35131ef18-- --5ae4ba4c466da4b3a4842affd55f0cccceffa06d9b6773f36fe46ef17f9c Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=v4-0001-Allow-SIGINT-to-cancel-psql-database-reconnection.patch Content-Type: text/x-patch; charset=utf-8; name=v4-0001-Allow-SIGINT-to-cancel-psql-database-reconnection.patch RnJvbSA3M2E5NWJjNTM3ZjIwNWNkYWM1NjdmM2YxODYwYjA4Y2Y4MzIzZTE3IE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBUcmlzdGFuIFBhcnRpbiA8dHJpc3RhbkBuZW9uLnRlY2g+CkRh dGU6IE1vbiwgMjQgSnVsIDIwMjMgMTE6MTI6NTkgLTA1MDAKU3ViamVjdDogW1BBVENIIHY0XSBB bGxvdyBTSUdJTlQgdG8gY2FuY2VsIHBzcWwgZGF0YWJhc2UgcmVjb25uZWN0aW9ucwoKQWZ0ZXIg aW5zdGFsbGluZyB0aGUgU0lHSU5UIGhhbmRsZXIgaW4gcHNxbCwgU0lHSU5UIGNhbiBubyBsb25n ZXIgY2FuY2VsCmRhdGFiYXNlIHJlY29ubmVjdGlvbnMuIEZvciBpbnN0YW5jZSwgaWYgdGhlIHVz ZXIgc3RhcnRzIGEgcmVjb25uZWN0aW9uCmFuZCB0aGVuIG5lZWRzIHRvIGRvIHNvbWUgZm9ybSBv ZiBpbnRlcmFjdGlvbiAoaWUgcHNxbCBpcyBwb2xsaW5nKSwKdGhlcmUgaXMgbm8gd2F5IHRvIGNh bmNlbCB0aGUgcmVjb25uZWN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B2YWx1ZXMsIGZhbHNlKTsKKwkJbl9jb25uID0gUFFj b25uZWN0U3RhcnRQYXJhbXMoa2V5d29yZHMsIHZhbHVlcywgZmFsc2UpOwogCiAJCXBnX2ZyZWUo a2V5d29yZHMpOwogCQlwZ19mcmVlKHZhbHVlcyk7CiAKKwkJd2hpbGUgKHRydWUpIHsKKwkJCWlu dAkJc29ja2V0OworCisJCQlpZiAoQ2FuY2VsUmVxdWVzdGVkKQorCQkJCWJyZWFrOworCisJCQlz b2NrZXQgPSBQUXNvY2tldChuX2Nvbm4pOworCQkJaWYgKHNvY2tldCA9PSAtMSkKKwkJCQlicmVh azsKKworCQkJc3dpdGNoIChQUWNvbm5lY3RQb2xsKG5fY29ubikpIHsKKwkJCWNhc2UgUEdSRVNf UE9MTElOR19PSzoKKwkJCWNhc2UgUEdSRVNfUE9MTElOR19GQUlMRUQ6CisJCQkJYnJlYWs7CisJ CQljYXNlIFBHUkVTX1BPTExJTkdfUkVBRElORzoKKwkJCWNhc2UgUEdSRVNfUE9MTElOR19XUklU SU5HOgorCQkJCWNvbnRpbnVlOworCQkJY2FzZSBQR1JFU19QT0xMSU5HX0FDVElWRToKKwkJCQlw Z191bnJlYWNoYWJsZSgpOworCQkJfQorCQl9CisKIAkJaWYgKFBRc3RhdHVzKG5fY29ubikgPT0g Q09OTkVDVElPTl9PSykKIAkJCWJyZWFrOwogCi0tIApUcmlzdGFuIFBhcnRpbgpOZW9uIChodHRw czovL25lb24udGVjaCkKCg== --5ae4ba4c466da4b3a4842affd55f0cccceffa06d9b6773f36fe46ef17f9c--