pg.ddx.io pgsql-committers@postgresql.org mailing list archive
help / color / mirror / Atom feedpgsql: Fix stream abort for a transaction that was never streamed.
3+ messages / 1 participants
[nested] [flat]
* pgsql: Fix stream abort for a transaction that was never streamed.
@ 2026-08-18 18:59 Masahiko Sawada <msawada@postgresql.org>
0 siblings, 0 replies; 3+ messages in thread
From: Masahiko Sawada @ 2026-08-18 18:59 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Fix stream abort for a transaction that was never streamed.
Commit 072ee847ad4 taught logical decoding to discard the changes of a
transaction that is already known to be aborted when it is picked for
eviction. That path reuses ReorderBufferTruncateTXN(), which marks
every subtransaction that still has in-memory changes as
streamed. Since nothing is streamed in that path, and the top-level
transaction is never marked, a subtransaction ends up flagged as
streamed even though the output plugin has never seen it. Decoding the
subsequent abort record then makes ReorderBufferAbort() invoke the
stream_abort callback for that subtransaction.
For pgoutput this sends a Stream Abort ('A') message to a subscriber
that requested streaming = off, and it does so regardless of the
negotiated protocol version, so even a client speaking a version that
predates transaction streaming receives a message it cannot
parse. test_decoding dereferences a NULL pointer and crashes, since it
allocates its per-transaction state in the begin or stream start
callback, neither of which runs for a transaction discarded as
aborted.
This commit fixes this by marking a subtransaction as streamed only
when it has changes and its top-level transaction is already marked as
streamed. All streaming call sites mark the top-level transaction
before truncating it, so their behavior is unchanged, while the
abort-discard path never marks the top-level transaction and therefore
now leaves its subtransactions unmarked.
Backpatch to v18, where commit 072ee847ad4 was introduced.
Bug: #19616
Reported-by: Tyler Smart <tyler@smarts.io>
Author: Andrey Rachitskiy <pl0h0yp1@gmail.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Discussion: https://postgr.es/m/19616-f6153af509910853@postgresql.org
Backpatch-through: 18
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/aa4c52b808f76870f80189757af7217358544d60
Modified Files
--------------
contrib/test_decoding/expected/stream.out | 23 +++++++++++++++
contrib/test_decoding/sql/stream.sql | 17 +++++++++++
src/backend/replication/logical/reorderbuffer.c | 38 ++++++++++++++++---------
3 files changed, 64 insertions(+), 14 deletions(-)
^ permalink raw reply [nested|flat] 3+ messages in thread
* pgsql: Fix stream abort for a transaction that was never streamed.
@ 2026-08-18 18:59 Masahiko Sawada <msawada@postgresql.org>
0 siblings, 0 replies; 3+ messages in thread
From: Masahiko Sawada @ 2026-08-18 18:59 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Fix stream abort for a transaction that was never streamed.
Commit 072ee847ad4 taught logical decoding to discard the changes of a
transaction that is already known to be aborted when it is picked for
eviction. That path reuses ReorderBufferTruncateTXN(), which marks
every subtransaction that still has in-memory changes as
streamed. Since nothing is streamed in that path, and the top-level
transaction is never marked, a subtransaction ends up flagged as
streamed even though the output plugin has never seen it. Decoding the
subsequent abort record then makes ReorderBufferAbort() invoke the
stream_abort callback for that subtransaction.
For pgoutput this sends a Stream Abort ('A') message to a subscriber
that requested streaming = off, and it does so regardless of the
negotiated protocol version, so even a client speaking a version that
predates transaction streaming receives a message it cannot
parse. test_decoding dereferences a NULL pointer and crashes, since it
allocates its per-transaction state in the begin or stream start
callback, neither of which runs for a transaction discarded as
aborted.
This commit fixes this by marking a subtransaction as streamed only
when it has changes and its top-level transaction is already marked as
streamed. All streaming call sites mark the top-level transaction
before truncating it, so their behavior is unchanged, while the
abort-discard path never marks the top-level transaction and therefore
now leaves its subtransactions unmarked.
Backpatch to v18, where commit 072ee847ad4 was introduced.
Bug: #19616
Reported-by: Tyler Smart <tyler@smarts.io>
Author: Andrey Rachitskiy <pl0h0yp1@gmail.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Discussion: https://postgr.es/m/19616-f6153af509910853@postgresql.org
Backpatch-through: 18
Branch
------
REL_19_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/e4f16fda6e1479b4fdfa6dc31dd41f48c86426fe
Modified Files
--------------
contrib/test_decoding/expected/stream.out | 23 +++++++++++++++
contrib/test_decoding/sql/stream.sql | 17 +++++++++++
src/backend/replication/logical/reorderbuffer.c | 38 ++++++++++++++++---------
3 files changed, 64 insertions(+), 14 deletions(-)
^ permalink raw reply [nested|flat] 3+ messages in thread
* pgsql: Fix stream abort for a transaction that was never streamed.
@ 2026-08-18 18:59 Masahiko Sawada <msawada@postgresql.org>
0 siblings, 0 replies; 3+ messages in thread
From: Masahiko Sawada @ 2026-08-18 18:59 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Fix stream abort for a transaction that was never streamed.
Commit 072ee847ad4 taught logical decoding to discard the changes of a
transaction that is already known to be aborted when it is picked for
eviction. That path reuses ReorderBufferTruncateTXN(), which marks
every subtransaction that still has in-memory changes as
streamed. Since nothing is streamed in that path, and the top-level
transaction is never marked, a subtransaction ends up flagged as
streamed even though the output plugin has never seen it. Decoding the
subsequent abort record then makes ReorderBufferAbort() invoke the
stream_abort callback for that subtransaction.
For pgoutput this sends a Stream Abort ('A') message to a subscriber
that requested streaming = off, and it does so regardless of the
negotiated protocol version, so even a client speaking a version that
predates transaction streaming receives a message it cannot
parse. test_decoding dereferences a NULL pointer and crashes, since it
allocates its per-transaction state in the begin or stream start
callback, neither of which runs for a transaction discarded as
aborted.
This commit fixes this by marking a subtransaction as streamed only
when it has changes and its top-level transaction is already marked as
streamed. All streaming call sites mark the top-level transaction
before truncating it, so their behavior is unchanged, while the
abort-discard path never marks the top-level transaction and therefore
now leaves its subtransactions unmarked.
Backpatch to v18, where commit 072ee847ad4 was introduced.
Bug: #19616
Reported-by: Tyler Smart <tyler@smarts.io>
Author: Andrey Rachitskiy <pl0h0yp1@gmail.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Discussion: https://postgr.es/m/19616-f6153af509910853@postgresql.org
Backpatch-through: 18
Branch
------
REL_18_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/caa463e3f8d2b9c1441e6a59c50f90b8598439f3
Modified Files
--------------
contrib/test_decoding/expected/stream.out | 23 +++++++++++++++
contrib/test_decoding/sql/stream.sql | 17 +++++++++++
src/backend/replication/logical/reorderbuffer.c | 38 ++++++++++++++++---------
3 files changed, 64 insertions(+), 14 deletions(-)
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2026-08-18 18:59 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-08-18 18:59 pgsql: Fix stream abort for a transaction that was never streamed. Masahiko Sawada <msawada@postgresql.org>
2026-08-18 18:59 pgsql: Fix stream abort for a transaction that was never streamed. Masahiko Sawada <msawada@postgresql.org>
2026-08-18 18:59 pgsql: Fix stream abort for a transaction that was never streamed. Masahiko Sawada <msawada@postgresql.org>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox