From: | Kirill Reshke <reshkekirill(at)gmail(dot)com> |
---|---|
To: | Dilip Kumar <dilipbalaut(at)gmail(dot)com> |
Cc: | exclusion(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org |
Subject: | Re: BUG #19026: ResourceOwnerForget can't find owner for invalid plancache |
Date: | 2025-08-20 11:43:32 |
Message-ID: | CALdSSPijvR-X693FPJfT2==7Otb=Ft6NrPQ02r4i1c8MnW_8tQ@mail.gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | 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(at)gmail(dot)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 | Content-Type | Size |
---|---|---|
v1-0001-Forget-cached-plan-on-transaction-rollback-in-SQL.patch | application/octet-stream | 786 bytes |
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2025-08-20 12:09:10 | Re: The memory usage is positively correlated with the number of partition tables when pg_get_expr is called. |
Previous Message | Dilip Kumar | 2025-08-20 11:21:07 | Re: BUG #19026: ResourceOwnerForget can't find owner for invalid plancache |