| From: | Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com> |
|---|---|
| To: | "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com> |
| Cc: | Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, vignesh C <vignesh21(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: [PATCH] Fix stale relation close in sequence synchronization |
| Date: | 2026-04-28 12:34:40 |
| Message-ID: | CAJTYsWUSQpw_umMCNUfY7Tbwe_VeYxQHGNLRL+bwTfu36XEOBQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
On Tue, 28 Apr 2026 at 17:44, Hayato Kuroda (Fujitsu) <
kuroda(dot)hayato(at)fujitsu(dot)com> wrote:
> Dear Ayush,
>
> > I found a crash in the logical replication sequence synchronization
> worker
> > when the publisher returns NULL sequence data for a sequence after at
> least
> > one sequence in the same sync batch has already been processed.
>
> Good catch. I confirmed the HEAD can crash with your added test.
>
Thanks for checking and confirming the crash.
>
> > The attached patch clears the output Relation pointer at the start of
> > get_and_validate_seq_info() and clears the local pointer in
> copy_sequences()
> > after closing it. That keeps early returns from reusing a relation from a
> > previous row.
>
> To confirm; can't we declare the sequence_rel in the inner-loop? My first
> impression was the bug caused by the wrong lifetime. Are there any other
> thoughts around here?
I agree that declaring sequence_rel in the tuple-processing loop is
cleaner. The relation belongs only to the current publisher result row,
so limiting the variable's lifetime makes the intended ownership clearer
and prevents any value from carrying over to the next row.
I have kept the initialization of the output argument in
get_and_validate_seq_info(), so every return path leaves it in a defined
state. In v2, the caller-side pointer is declared inside the inner loop,
and the explicit reset after table_close() is no longer needed.
Attached is v2 with that change.
Regards,
Ayush
| Attachment | Content-Type | Size |
|---|---|---|
| v2-0001-Fix-stale-relation-close-in-sequence-synchronization.patch | application/octet-stream | 4.5 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | vignesh C | 2026-04-28 13:18:22 | Re: [PATCH] Fix stale relation close in sequence synchronization |
| Previous Message | Hayato Kuroda (Fujitsu) | 2026-04-28 12:13:59 | RE: [PATCH] Fix stale relation close in sequence synchronization |