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 1kTHry-0008IT-Q9 for pgsql-committers@arkaria.postgresql.org; Fri, 16 Oct 2020 05:01:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kTHrx-0000Ic-K3 for pgsql-committers@arkaria.postgresql.org; Fri, 16 Oct 2020 05:01:33 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kTHrx-0000IV-ES for pgsql-committers@lists.postgresql.org; Fri, 16 Oct 2020 05:01:33 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kTHrq-0008JR-SU for pgsql-committers@lists.postgresql.org; Fri, 16 Oct 2020 05:01:32 +0000 Received: from hnk.local (sp1-75-202-185.msb.spmode.ne.jp [1.75.202.185]) by oss.nttdata.com (Postfix) with ESMTPSA id 267986259A; Fri, 16 Oct 2020 14:01:23 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.3 at oss.nttdata.com Subject: Re: pgsql: postgres_fdw: reestablish new connection if cached one is detect From: Fujii Masao To: Tom Lane Cc: Michael Paquier , Fujii Masao , pgsql-committers@lists.postgresql.org References: <20201007021347.GD2256@paquier.xyz> <14cd32c8-9532-47b8-77d4-b81eb3b192ea@oss.nttdata.com> <78d509fe-f87a-7046-672a-f86cb6f6957d@oss.nttdata.com> <2461600.1602164840@sss.pgh.pa.us> <2943611.1602375376@sss.pgh.pa.us> <53c3deb8-666d-fc4c-f0b5-e8c397bc6250@oss.nttdata.com> <3483167.1602614058@sss.pgh.pa.us> <3227bd19-60b2-9c79-7b7b-f792e5463dbe@oss.nttdata.com> Message-ID: Date: Fri, 16 Oct 2020 14:01:22 +0900 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.12.1 MIME-Version: 1.0 In-Reply-To: <3227bd19-60b2-9c79-7b7b-f792e5463dbe@oss.nttdata.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2020/10/15 16:21, Fujii Masao wrote: > > > On 2020/10/14 3:34, Tom Lane wrote: >> Fujii Masao writes: >>> On 2020/10/11 9:16, Tom Lane wrote: >>>> Meanwhile, now that I've looked at commit 32a9c0bdf, I'm not very >>>> happy with it: >>>> >>>> * The control flow seems rather forced.  I think it was designed >>>> on the assumption that reindenting the existing code is forbidden. >> >>> Isn't it simpler and easier-to-read to just reestablish new connection again >>> in the retry case instead of using a loop because we retry only once? >>> Patch attached. >> >> Yeah, that seems better. >> >>>> * As is so often true of proposed patches in which PG_CATCH is >>>> thought to be an adequate way to catch an error, this is just >>>> unbelievably fragile.  It will break, and badly so, if it catches >>>> an error that is anything other than what it is expecting ... >>>> and it's not even particularly trying to verify that the error is >>>> what it's expecting.  It might be okay, or at least a little bit >>>> harder to break, if it verified that the error's SQLSTATE is >>>> ERRCODE_CONNECTION_FAILURE. >> >>> "PQstatus()==CONNECTION_BAD" was checked for that purpose. But that's not enough? >>> Anyway, in the patch, I changed the code so that sqlstate==ERRCODE_CONNECTION_FAILURE >>> is checked. >> >> The reason I'm concerned about this is that we could potentially throw an >> elog(ERROR) somewhere between return from libpq and the expected ereport >> call in pgfdw_report_error.  It wouldn't be wise to ignore such a >> condition (it might be out-of-memory or some such). > > Understood. > > >> Personally I'd code the check with explicit tests for *both* >> PQstatus()==CONNECTION_BAD and sqlstate==ERRCODE_CONNECTION_FAILURE, >> rather than just asserting that the latter must imply the former. >> By my reading, pgfdw_report_error will report ERRCODE_CONNECTION_FAILURE >> for any libpq-originated error condition, but not all of those will >> set CONNECTION_BAD. > > Yes, this makes sense. I updated the patch so that both sqlstate and > PQstatus() are checked. Patch attached. > > >> Other than that, this seems reasonable by eyeball (I didn't do any >> testing). > > Thanks! Barring any objection, I will commit it. Pushed. Thanks! Regards, -- Fujii Masao Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATION