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 1l5LrV-00026O-QT for pgsql-hackers@arkaria.postgresql.org; Fri, 29 Jan 2021 04:58:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l5LrU-0000hQ-Ll for pgsql-hackers@arkaria.postgresql.org; Fri, 29 Jan 2021 04:58:24 +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 1l5LrU-0000hJ-Fh for pgsql-hackers@lists.postgresql.org; Fri, 29 Jan 2021 04:58:24 +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 1l5LrM-0001VK-W6 for pgsql-hackers@lists.postgresql.org; Fri, 29 Jan 2021 04:58:23 +0000 Received: from hnk.local (p2112118-ipbf2507funabasi.chiba.ocn.ne.jp [123.216.63.118]) by oss.nttdata.com (Postfix) with ESMTPSA id 5CBC26285D; Fri, 29 Jan 2021 13:58:12 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.3 at oss.nttdata.com Subject: Re: [PATCH] postgres_fdw connection caching - cause remote sessions linger till the local session exit To: Tom Lane , Bharath Rupireddy Cc: PostgreSQL Hackers References: <64ee084b-1368-e044-debd-69cc156276c6@oss.nttdata.com> <39259f30-897c-ceaf-8a1e-78fe2db398cb@oss.nttdata.com> <2147113.1611644754@sss.pgh.pa.us> <1b4d7c4f-a9f9-08f0-295d-de6ec0d5def5@oss.nttdata.com> <3c20e3e6-1127-17f4-7725-a860b394076c@oss.nttdata.com> <73fc5ae4-3c54-1262-4533-f8c547de2e60@oss.nttdata.com> <2688508.1611865371@sss.pgh.pa.us> <2724627.1611886184@sss.pgh.pa.us> From: Fujii Masao Message-ID: Date: Fri, 29 Jan 2021 13:58:11 +0900 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: <2724627.1611886184@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2021/01/29 11:09, Tom Lane wrote: > Bharath Rupireddy writes: >> On Fri, Jan 29, 2021 at 1:52 AM Tom Lane wrote: >>> https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=trilobite&dt=2021-01-26%2019%3A59%3A40 >>> This is a CLOBBER_CACHE_ALWAYS build, so I suspect what it's >>> telling us is that the patch's behavior is unstable in the face >>> of unexpected cache flushes. > >> Thanks a lot! It looks like the syscache invalidation messages are >> generated too frequently with -DCLOBBER_CACHE_ALWAYS build due to >> which pgfdw_inval_callback gets called many times in which the cached >> entries are marked as invalid and closed if they are not used in the >> txn. The new function postgres_fdw_get_connections outputs the >> information of the cached connections such as name if the connection >> is still open and their validity. Hence the output of the >> postgres_fdw_get_connections became unstable in the buildfarm member. >> I will further analyze making tests stable, meanwhile any suggestions >> are welcome. > > I do not think you should regard this as "we need to hack the test > to make it stable". I think you should regard this as "this is a > bug". A cache flush should not cause user-visible state changes. > In particular, the above analysis implies that you think a cache > flush is equivalent to end-of-transaction, which it absolutely > is not. > > Also, now that I've looked at pgfdw_inval_callback, it scares > the heck out of me. Actually disconnecting a connection during > a cache inval callback seems quite unsafe --- what if that happens > while we're using the connection? If the connection is still used in the transaction, pgfdw_inval_callback() marks it as invalidated and doesn't close it. So I was not thinking that this is so unsafe. The disconnection code in pgfdw_inval_callback() was added in commit e3ebcca843 to fix connection leak issue, and it's back-patched. If this change is really unsafe, we need to revert it immediately at least from back branches because the next minor release is scheduled soon. BTW, even if we change pgfdw_inval_callback() so that it doesn't close the connection at all, ISTM that the results of postgres_fdw_get_connections() would not be stable because entry->invalidated would vary based on whether CLOBBER_CACHE_ALWAYS is used or not. Regards, -- Fujii Masao Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATION