| From: | Heikki Linnakangas <hlinnaka(at)iki(dot)fi> |
|---|---|
| To: | Matheus Alcantara <matheusssilv97(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
| Cc: | adoros(at)starfishstorage(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org, rmt(at)lists(dot)postgresql(dot)org |
| Subject: | Re: BUG #19480: PL/Python SRF crashes (SIGSEGV) when function is replaced mid-iteration: use-after-free in PLy_funct |
| Date: | 2026-06-17 15:30:30 |
| Message-ID: | c07f8261-4c65-47da-bb97-5a2246816b57@iki.fi |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
On 05/06/2026 22:35, Matheus Alcantara wrote:
> On 05/06/26 16:11, Tom Lane wrote:
>> "Matheus Alcantara" <matheusssilv97(at)gmail(dot)com> 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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Nathan Bossart | 2026-06-17 15:43:06 | Re: BUG #19480: PL/Python SRF crashes (SIGSEGV) when function is replaced mid-iteration: use-after-free in PLy_funct |
| Previous Message | Andrey Rachitskiy | 2026-06-17 09:57:48 | Re: BUG #19458: OOM killer in jsonb_path_exists_opr (@?) with malformed JSONPath containing non-existent variables |