pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Fujii Masao <masao.fujii@oss.nttdata.com>
Cc: Michael Paquier <michael@paquier.xyz>
Cc: Fujii Masao <fujii@postgresql.org>
Cc: pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: postgres_fdw: reestablish new connection if cached one is detect
Date: Tue, 13 Oct 2020 14:34:18 -0400
Message-ID: <3483167.1602614058@sss.pgh.pa.us> (raw)
In-Reply-To: <53c3deb8-666d-fc4c-f0b5-e8c397bc6250@oss.nttdata.com>
References: <E1kPc9v-0005L4-2l@gemulon.postgresql.org>
	<20201007021347.GD2256@paquier.xyz>
	<14cd32c8-9532-47b8-77d4-b81eb3b192ea@oss.nttdata.com>
	<fb96a78e-54ad-832f-b2be-d589abdfd7df@oss.nttdata.com>
	<78d509fe-f87a-7046-672a-f86cb6f6957d@oss.nttdata.com>
	<eeec0120-9ca1-bd20-a00b-5fc5f2c862a1@oss.nttdata.com>
	<2461600.1602164840@sss.pgh.pa.us>
	<2943611.1602375376@sss.pgh.pa.us>
	<53c3deb8-666d-fc4c-f0b5-e8c397bc6250@oss.nttdata.com>

Fujii Masao <masao.fujii@oss.nttdata.com> 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).

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.

Other than that, this seems reasonable by eyeball (I didn't do any
testing).

			regards, tom lane





view thread (13+ messages)  latest in thread

Message-ID: <3483167.1602614058@sss.pgh.pa.us>
Permalink:  ../3483167.1602614058@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3483167.1602614058@sss.pgh.pa.us

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, masao.fujii@oss.nttdata.com, michael@paquier.xyz, fujii@postgresql.org
  Subject: Re: pgsql: postgres_fdw: reestablish new connection if cached one is detect
  In-Reply-To: <3483167.1602614058@sss.pgh.pa.us>
  References: <E1kPc9v-0005L4-2l@gemulon.postgresql.org> <20201007021347.GD2256@paquier.xyz> <14cd32c8-9532-47b8-77d4-b81eb3b192ea@oss.nttdata.com> <fb96a78e-54ad-832f-b2be-d589abdfd7df@oss.nttdata.com> <78d509fe-f87a-7046-672a-f86cb6f6957d@oss.nttdata.com> <eeec0120-9ca1-bd20-a00b-5fc5f2c862a1@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>

* 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