Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fzbGB-0003zV-6K for pgsql-bugs@arkaria.postgresql.org; Tue, 11 Sep 2018 05:30:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fzbG7-00047u-CV for pgsql-bugs@arkaria.postgresql.org; Tue, 11 Sep 2018 05:30:43 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fzbG7-00047m-3X for pgsql-bugs@lists.postgresql.org; Tue, 11 Sep 2018 05:30:43 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fzbG4-0002DM-15 for pgsql-bugs@lists.postgresql.org; Tue, 11 Sep 2018 05:30:41 +0000 Received: from [192.168.127.1] (port=47383 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.88 (FreeBSD)) (envelope-from ) id 1fzbG0-0009QM-BX; Tue, 11 Sep 2018 05:30:36 +0000 Received: from [127.0.0.1] (port=31682 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1fzbFz-000736-Ku; Tue, 11 Sep 2018 05:30:35 +0000 From: Andrew Gierth To: pgsql-bugs@lists.postgresql.org, do.daisuke@gmail.com Subject: Re: BUG #15379: Release process of the index access method is not called when an error occurs. In-Reply-To: <153664176892.23144.11307374381540165215@wrigleys.postgresql.org> (PG Bug reporting form's message of "Tue, 11 Sep 2018 04:56:08 +0000") Message-ID: <877ejsr4mw.fsf@news-spur.riddles.org.uk> References: <153664176892.23144.11307374381540165215@wrigleys.postgresql.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Tue, 11 Sep 2018 06:30:35 +0100 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "PG" == PG Bug reporting form writes: PG> When an error occurs in `SELECT FOR UPDATE` using an index, release PG> process of the index access method is not called. That's true in general for all errors. PG> At this time, the index access method ambeginscan() is called but PG> since amendscan() is not called, ambeginscan() can not properly PG> release the resource set in IndexScanDesc::opaque. Any resources that you allocate for the index scan have to be such that they get released automatically even on error paths: memory allocation is handled by the memory context system, things like buffer pins are handled by the ResourceOwner mechanism; locks are released by (sub)transaction abort. PG> Solution: PG> For example, if an error occurs while calling PortalRun() in PG> exec_simple_query() of src/backend/tcop/postgresq.c, amendscan() PG> will not be called because PortalDrop() will not be called. PG> Therefore, it is good to postpone even when an error occurs as PG> follows. Your solution is hopeless for many reasons, not least of which is the fact that an error while running the portal will cause it to be marked as failed, and executor shutdown will not be run for a failed portal. -- Andrew (irc:RhodiumToad)