Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e0FEY-00010s-Gj for pgsql-bugs@arkaria.postgresql.org; Thu, 05 Oct 2017 23:07:14 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e0FEX-0006y3-KU for pgsql-bugs@arkaria.postgresql.org; Thu, 05 Oct 2017 23:07:13 +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.84_2) (envelope-from ) id 1e0FDo-0005CC-AQ for pgsql-bugs@postgresql.org; Thu, 05 Oct 2017 23:06:28 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e0F8g-0004R2-T6 for pgsql-bugs@postgresql.org; Thu, 05 Oct 2017 23:01:16 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 1239420DCA; Thu, 5 Oct 2017 19:01:08 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute5.internal (MEProxy); Thu, 05 Oct 2017 19:01:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=fm1; bh=d7XrdeetM9N8xUFYhH BAzmJuqxHeo7XAG07Pxme5Rxs=; b=FqcQ0fVBqnH+31BXMPUnbZ7nUo6i6WJ1z0 xxNCdcWe3I7Tf9DEFEcmgNqlNw7+pWbmGfTHod6jgJCcKpM084U6maUXOa8FMc3l DrnYAcU78XuqaM1fV8TdleXf37eNOV9aJVTVrY2rLCGwuRfpcInJMBkLr80CziMo 4PwITJA77RqHTLi5RfrRdGJUWTv3ZOp8ror3X6G15CvGlzk4Zmf11ZpWvCmRwuR0 uORJz9Vy/OYCGpci/dlvSD3Q3FEdnyiGZOzy/Bz7S1a1M3VvfdNOM54M+nk3yiyZ xDGitXGSD9SjA1FE6HpKLjwcYqTdvN9s8faMHCPJsjQjwfCAruiA== X-ME-Sender: X-Sasl-enc: EauaQUhk6jRNnavB40A3EgnNOMsdsbt+2wG6UREuF1Jw 1507244467 Received: from intern.anarazel.de (unknown [172.58.35.147]) by mail.messagingengine.com (Postfix) with ESMTPA id 9DF057FA70; Thu, 5 Oct 2017 19:01:07 -0400 (EDT) Date: Thu, 5 Oct 2017 16:01:05 -0700 From: Andres Freund To: Tom Lane Cc: Michael Paquier , Ben Chobot , PostgreSQL mailing lists Subject: Re: pg_logical_slot_peek_changes crashes postgres when called from inside pl/pgsql Message-ID: <20171005230105.qv2yrtadbkbc5y5r@alap3.anarazel.de> References: <73FBA179-C68C-4540-9473-71E865408B15@silentmedia.com> <8637.1507217920@sss.pgh.pa.us> <20171005211058.z5obk2c2e7zvauk6@alap3.anarazel.de> <32374.1507239819@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <32374.1507239819@sss.pgh.pa.us> List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Hi, On 2017-10-05 17:43:39 -0400, Tom Lane wrote: > Andres Freund writes: > > On 2017-10-05 11:38:40 -0400, Tom Lane wrote: > >> I wonder why ReorderBufferCommit does this: > >> ... > > > I'm not sure what the problem is that you're seeing? > > Nah, I take that back. The AbortCurrentTransaction call looks funny > (and is sadly underdocumented) but it's not invalid to call it and > then call RollbackAndReleaseCurrentSubTransaction. It's not perfectly documented, but there's some: /* * Decoding needs access to syscaches et al., which in turn use * heavyweight locks and such. Thus we need to have enough state around to * keep track of those. The easiest way is to simply use a transaction * internally. That also allows us to easily enforce that nothing writes * to the database by checking for xid assignments. * * When we're called via the SQL SRF there's already a transaction * started, so start an explicit subtransaction there. */ ... /* * Aborting the current (sub-)transaction as a whole has the right * semantics. We want all locks acquired in here to be released, not * reassigned to the parent and we do not want any database access * have persistent effects. */ > 2. The "MemoryContextResetAndDeleteChildren(_SPI_current->execCxt)" > call, further up, is deleting a still-live executor state tree, > as well as the logical-decoding context that is a child of that > executor query context. So if you get past the Assert you'll still > crash later on. Right. That's why just adding found && to the entire if "works", as it avoids that part as well. > I'm not sure about a good way to fix #2 without re-introducing the memory > leaks that call was added to fix (cf 7ec1c5a86). It's slightly annoying > at this point that we got rid of the SPI_push/SPI_pop mechanism, because > we could perhaps have used a check of the _SPI_curid value to distinguish > a SPI context we should clean up from one we shouldn't. But that ship has > sailed, and even if we wanted to undo that change there'd still be the > matter of how to fix the bugs that prompted removing SPI_push/SPI_pop. I think I don't fully understand what 7ec1c5a86 is trying to achieve. Unfortunately reading the commit message and comment hasn't cleared it up much so far. Why do we want to clean up memory in a subtransaction that's above the one aborted? I can't yet meaningfully comment on your proposals before fully understanding, sorry. Greetings, Andres Freund -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs