Re: BUG #19026: ResourceOwnerForget can't find owner for invalid plancache - Mailing list pgsql-bugs

From Kirill Reshke
Subject Re: BUG #19026: ResourceOwnerForget can't find owner for invalid plancache
Date
Msg-id CALdSSPijvR-X693FPJfT2==7Otb=Ft6NrPQ02r4i1c8MnW_8tQ@mail.gmail.com
Whole thread Raw
In response to Re: BUG #19026: ResourceOwnerForget can't find owner for invalid plancache  (Dilip Kumar <dilipbalaut@gmail.com>)
Responses Re: BUG #19026: ResourceOwnerForget can't find owner for invalid plancache
List pgsql-bugs
Hi!


First of all, Alexander, thank you for the excellent bug report!

On Wed, 20 Aug 2025 at 16:21, Dilip Kumar <dilipbalaut@gmail.com> wrote:
>
> > ERROR:  XX000: plancache reference 0x643ae41a7d98 is not owned by resource
> > owner Portal
> > CONTEXT:  SQL function "part_hashint4_noop" during startup
> > LOCATION:  ResourceOwnerForget, resowner.c:618
>
> The problem is in init_execution_state() we store the
>
> On error resource owner will be released, but that references are
> still maintained in the plan and cowner in fcache, but on error the
> transaction will be aborted and this resource owner will be released.
> So next time when we try to clean up, it will access invalid memory.
> So a simple fix would be to cleanup on error as attached POC.
>
> --
> Regards,
> Dilip Kumar
> Google

As for the patch: should we add some regression test for this?
Also, I'm not terribly sure  what this fix does is the right thing to do.
Doesn’t it break some layer of abstraction here? My understanding is
that on transaction rollback, all resources should be freed in the
ResourceOwnerRelease
function and friends. Namely, the ReleaseCachedPlan call we make
before elog(ERROR) is breaking logic. Am I wrong?
For this sql cache there exists sql_exec_error_callback, which is
probably a better place to clean up on error.

How about attached?


--
Best regards,
Kirill Reshke

Attachment

pgsql-bugs by date:

Previous
From: Dilip Kumar
Date:
Subject: Re: BUG #19026: ResourceOwnerForget can't find owner for invalid plancache
Next
From: Tom Lane
Date:
Subject: Re: The memory usage is positively correlated with the number of partition tables when pg_get_expr is called.