| From: | Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com> |
|---|---|
| To: | shveta malik <shveta(dot)malik(at)gmail(dot)com> |
| Cc: | Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>, SATYANARAYANA NARLAPURAM <satyanarlapuram(at)gmail(dot)com>, Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, vignesh C <vignesh21(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: [PATCH] Release replication slot on error in SQL-callable slot functions |
| Date: | 2026-08-04 02:20:00 |
| Message-ID: | CALj2ACUD_K5zBgXD3ebYmhmouJx91fq+aiLeD8HSuC6xnYvj3g@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
On Sun, Aug 2, 2026 at 10:28 PM shveta malik <shveta(dot)malik(at)gmail(dot)com> wrote:
>
> Bharath, I could not find any issue in my basic testing,
Thanks, Shveta, for reviewing!
> although I
> would like to understand this part a bit better:
>
> + if (isCommit)
> + {
> + acquiredInSubId = parentSubid;
> + return;
> + }
>
> How can we reach this block? In a non-error scenario, it seems that by
> the time AtEOSubXact_ReplicationSlot() is invoked, the slot has
> already been released, and we return earlier from 'if (acquiredInSubId
> != mySubid)' block. I could not find a case where:
>
> a) the slot is acquired in the current subtransaction, b) the
> subtransaction commits (isCommit == true), and c) the slot is still
> held when AtEOSubXact_ReplicationSlot() is invoked.
>
> Could you please explain what I am missing?
Yes, no caller hits this today. Each slot function releases the slot
before returning, so we take the early return and never reach the
commit branch with a slot still held. It is there for a future slot
function that acquires the slot but never releases it (rare case). On
commit we pass the slot to the parent so that if an ancestor later
aborts, the slot still gets released, the same way
AtEOSubXact_LargeObject() and AtEOSubXact_Files() do.
I checked this locally by making the pg_replication_slot_advance()
return while still holding the slot and running it through nested
PL/pgSQL exception blocks. With the handoff the outer abort releases
the slot, and dropping the handoff makes the slot leak and hit the
same issue reported in this thread. I can either enhance the comment
there to say it's currently unreachable and why we keep it, or turn it
into an assertion.
Thoughts?
--
Bharath Rupireddy
Amazon Web Services: https://aws.amazon.com
| From | Date | Subject | |
|---|---|---|---|
| Next Message | kid | 2026-08-04 02:33:12 | Re: Bug in logical decoding with DDL and subtransactions |
| Previous Message | Ewan Young | 2026-08-04 02:15:55 | Re: Fix error handling in getCopyDataMessage and pqFunctionCall3 |