RE: [PATCH] Fix stale relation close in sequence synchronization

Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>

From: "Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>
To: 'Ayush Tiwari' <ayushtiwari.slg01@gmail.com>
Cc: Amit Kapila <amit.kapila16@gmail.com>, vignesh C <vignesh21@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2026-04-28T12:13:59Z
Lists: pgsql-hackers
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.

> 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?

Added Vignesh in CC because he was a primary author.

Best regards,
Hayato Kuroda
FUJITSU LIMITED

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Fix BF failure introduced in commit 2bf6c9ff71.

  2. Fix double table_close of sequence_rel in copy_sequences().

  3. Fix BF failure introduced by commit b3f6b14cf4.