Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1prLrI-0000av-MI for pgsql-hackers@arkaria.postgresql.org; Tue, 25 Apr 2023 16:49:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1prLrG-0006pm-HI for pgsql-hackers@arkaria.postgresql.org; Tue, 25 Apr 2023 16:49:38 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1prLrG-0006pd-7a for pgsql-hackers@lists.postgresql.org; Tue, 25 Apr 2023 16:49:38 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1prLrD-0051IM-3Q for pgsql-hackers@lists.postgresql.org; Tue, 25 Apr 2023 16:49:37 +0000 Received: from [192.168.11.8] (p3342141-ipngn9201funabasi.chiba.ocn.ne.jp [180.15.124.141]) by oss.nttdata.com (Postfix) with ESMTPSA id 9C1DF606BC; Wed, 26 Apr 2023 01:49:28 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at oss.nttdata.com Message-ID: <53f03117-087f-5583-2c97-e82a3e9dc43e@oss.nttdata.com> Date: Wed, 26 Apr 2023 01:49:28 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: Issue in postgres_fdw causing unnecessary wait for cancel request reply To: Jelte Fennema , Kyotaro Horiguchi Cc: etsuro.fujita@gmail.com, pgsql-hackers@lists.postgresql.org References: <67cad2e7-f9c1-5eb0-a0be-99fd78571906@oss.nttdata.com> <20230417.173812.452521384661813597.horikyota.ntt@gmail.com> Content-Language: en-US From: Fujii Masao In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2023/04/21 16:39, Jelte Fennema wrote: >> In my opinion, PQconnectPoll and PQgetCancel should use the same >> parsing function or PQconnectPoll should set parsed values, making >> unnecessary for PQgetCancel to parse the same parameter >> again. > > Yes, I totally agree. So I think patch 0002 looks fine. It seems like we have reached a consensus to push the 0002 patch. As for back-patching, although the issue it fixes is trivial, it may be a good idea to back-patch to v12 where parse_int_param() was added, for easier back-patching in the future. Therefore I'm thinking to push the 0002 patch at first and back-patch to v12. >> Additionally, PQgetCancel should set appropriate error messages >> for all failure modes. > > I don't think that PQgetCancel should ever set error messages on the > provided conn object though. It's not part of the documented API and > it's quite confusing since there's actually no error on the connection > itself. That this happens for the keepalive parameter was an > unintended sideeffect of 5987feb70b combined with the fact that the > parsing is different. All those parsing functions should never error, > because setting up the connection should already have checked them. > > So I think the newly added libpq_append_conn_error calls in patch 0001 > should be removed. The AF_UNIX check and the new WARNING in pg_fdw > seem fine though. Sounds reasonable to me. Regarding the WARNING message, another idea is to pass the return value of PQgetCancel() directly to PQcancel() as follows. If NULL is passed, PQcancel() will detect it and set the proper error message to errbuf. Then the warning message "WARNING: could not send cancel request: PQcancel() -- no cancel object supplied" is output. This approach is similar to how dblink_cancel_query() does. Thought? ---------------- cancel = PQgetCancel(conn); if (!PQcancel(cancel, errbuf, sizeof(errbuf))) { ereport(WARNING, (errcode(ERRCODE_CONNECTION_FAILURE), errmsg("could not send cancel request: %s", errbuf))); PQfreeCancel(cancel); return false; } ---------------- Regards, -- Fujii Masao Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATION