Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wZsDz-001MHS-0S for pgsql-bugs@arkaria.postgresql.org; Wed, 17 Jun 2026 15:30:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wZsDy-006Z7i-0B for pgsql-bugs@arkaria.postgresql.org; Wed, 17 Jun 2026 15:30:42 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wZsDx-006Z7X-2Y; Wed, 17 Jun 2026 15:30:41 +0000 Received: from lahtoruutu.iki.fi ([2a0b:5c81:1c1::37]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wZsDv-00000000pCm-38nn; Wed, 17 Jun 2026 15:30:40 +0000 Received: from [10.0.2.15] (unknown [130.41.208.2]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4ggSVH1LGPz49PxG; Wed, 17 Jun 2026 18:30:31 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1781710232; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t5hWZLesV2dBusqXoH6ZFFKAtIR154V6GZg8iuA/84o=; b=AvmG8tESzm8zS0f5p4Wb2Fc9+IgGjBw5Y6cT92YrhEGGjjs2A6jBHXj0jWVYT7U56tgmgC zKL6JV3/svdayu2I23x9IRplgcOMJSJNTWlw+9kl3IcOoeiPXwwPPeiEdriHBR1GER6yFX fWcf5Ef/CEJAfhY3Q+vfR1X+aGUKia2GSns84n95keeWrYjsYlYYSJtqi3PKeSgf2Qq26z P26ERjvjvvME9t1RoI5G6/997iJMEzkRAZkGIqpCrWbSCzcyYC2YsiuVccrISUusauu7ly WqDGKCRjfMUfx7FaAsIIqqR0jIQjQiAA+fhuZqblASdyc+7KUuBIh5atiTiKLQ== ARC-Seal: i=1; a=rsa-sha256; d=iki.fi; s=lahtoruutu; cv=none; t=1781710232; b=HBzovy6MM4jdM9XiTIP4CjonuBDw6XGHK1cMh7GXR/QHvHE4YXFXPG++7Ho81czRXkiegn 69RNjTuoahR8VieDcdumo+PoQm/9O8eYePOdDcP4zfimR77KN9wj3h8shqEaoSKynV6Co8 L+Ww1TGzSojmw/untjERnOlAree4TxR+EiCAqmbfjFnstZlfaapYgnCmKqKD3QIzbPUTJl FomFy0ExGpmu+JsiENltUmgBAQkroEQaAdVMP9wKsSi908OOf12+21cL3R7q5o+D0tiZBJ OvHg1KxgGpCzWIXiI3twHd96AFkPtaROv5pUnamhv+Nt0kuHlAxmtlPiyk5Jbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1781710232; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t5hWZLesV2dBusqXoH6ZFFKAtIR154V6GZg8iuA/84o=; b=rV3gGDO3lwt5q8UJpiw2d/xMUii6BbKqomkvdB7XoOlvcCX3OL6/e/O807SAM+peFB6bS1 P9ZVBDtnK6pzQK2j1qu4fppQJdjUe6AwmMuLt5g8SKLqek68ejlpD0sLkZJ57IjvtGjhE4 VSyohS05Y2Xkx7A4qZ9CBvp/ehIHhgCNnUHLHtWjog2Pg/NkJ32fzfJFWdqkV+C44tCNfs qwlpk8kYr4lCmi4T5+0W3RjLJlwGuCo8J2Zb4c+kplSGQk7BUxPR+VFAs7bSSwiXb+BK+k o/bmGxR3o5L1zpCS0NbVRPKJQqrtVvHTZkBHzY8YmlxdHcHMq9LIhIk3iPtqpQ== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi Message-ID: Date: Wed, 17 Jun 2026 18:30:30 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #19480: PL/Python SRF crashes (SIGSEGV) when function is replaced mid-iteration: use-after-free in PLy_funct To: Matheus Alcantara , Tom Lane Cc: adoros@starfishstorage.com, pgsql-bugs@lists.postgresql.org, rmt@lists.postgresql.org References: <19480-f1f9fdce30462fc4@postgresql.org> <982975.1779981146@sss.pgh.pa.us> <2868592.1780356411@sss.pgh.pa.us> <3770958.1780686685@sss.pgh.pa.us> <9ecd2bd5-0fec-4ec2-9800-eb071683128c@gmail.com> Content-Language: en-US From: Heikki Linnakangas In-Reply-To: <9ecd2bd5-0fec-4ec2-9800-eb071683128c@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 05/06/2026 22:35, Matheus Alcantara wrote: > On 05/06/26 16:11, Tom Lane wrote: >> "Matheus Alcantara" writes: >>> On Mon Jun 1, 2026 at 8:26 PM -03, Tom Lane wrote: >>>> Actually ... if memory serves, SQL-language functions use ValuePerCall >>>> mode, so there probably already is a solution to this embedded in >>>> functions.c.  Did you look at that? >> >>> I dind't look at this before but this was exactly the right call. SQL >>> functions handle this by maintaining a per-call-site cache struct >>> (SQLFunctionCache) in fn_extra that holds both the pointer to the >>> long-lived hash entry and the execution state. The use_count is >>> incremented when we first obtain the function and decremented via a >>> MemoryContextCallback when fn_mcxt is deleted. >> >>> I've adapted the same approach for PL/Python. >> >> I've not read this patch yet but your high-level description seems >> on-target. >> >> Assuming the patch withstands review, there are three ways we could >> proceed: >> >> 1. Hold it for v20. >> >> 2. Sneak it into v19. >> >> 3. Treat it as a back-patchable fix and put it into v18 as well. >> (Going further back than v18 seems unreasonable because funccache.c >> doesn't exist before that, so we'd have to back-patch it too.) >> >> I do not think that #3 is really a great idea, mainly because the >> failure case doesn't seem very likely to be hit in production, >> and the lack of previous reports about this very ancient bug >> bears that out. >> >> I do find some attraction in #2, mainly because it would get the fix >> into the field a year earlier than #1.  But considering we're past >> beta1 it may be too late for #2 to be reasonable either. >> > > Yeah, this sounds a better option for me too, otherwise we can go with > #1. Back-patching this seems complicated, so I agree #3 does not seems a > good idea. > >> Looping in the RMT to see what they think... It's fine to still sneak it into v19. It's better to have it earlier, even if it means more churn during beta period. I haven't looked closely at the patch, but since it's a bug fix it would make sense to backpatch. If we're uncomfortable with backpatching it now, we could commit in master now, and backpatch later when we have more confidence. - Heikki