Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xPirF-00000000rTY-49j4 for pgsql-bugs@arkaria.postgresql.org; Sat, 07 Nov 2026 16:01:35 +0000 Received: from localhost ([127.0.0.1]:57122 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xPirF-000000049lg-43KD for pgsql-bugs@arkaria.postgresql.org; Sat, 07 Nov 2026 16:01:33 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]:44566) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xPVAD-000000023XL-0eRG for pgsql-bugs@lists.postgresql.org; Sat, 07 Nov 2026 01:24:13 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xPVA7-00000000jjG-0VAD for pgsql-bugs@lists.postgresql.org; Sat, 07 Nov 2026 01:24:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=gvlAYee2teZ0FyXGFXaiwVBmKSnnqVyBPJ931AjDA6o=; b=BgxEhtndqgqvcmdxOrwaEGJmX4 NCjTTAjbrx6U29RhtRHCstZggLjxqC0CWVrkppzMDVwqmlCqVUNkM0JcO3xkBD+jB5V0zOlVH1yrG ag6S5pBbg6Mxli4WRhLg96w3wlBnL80hfpXDgGxcN5aQBlAb2ikx0XXYb72VEdU6GK45GojYU+7zW YP8u2t3o/wvvgJ8eaZDEgyNtVZmIRqK31rhG0i0KWWGNHFf9264OtuxEeymA4Se5xorxXm4OVmN2D 90J2L+6/p3+UF7uKVyC6TlR94fynksf7hMgI8Gj2k5WYsDG3DzcNUk+AfNiIyVTvoMPQVmgUI0afB aIBUB3+g==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xPVA5-00000001ktB-3g5A for pgsql-bugs@lists.postgresql.org; Sat, 07 Nov 2026 01:24:05 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xPVA2-00000004P8k-2L8T for pgsql-bugs@lists.postgresql.org; Sat, 07 Nov 2026 01:24:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19839: Assert in ReorderBufferRestoreCleanup for aborted, spilled transaction To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: 125atishprak@gmail.com Reply-To: 125atishprak@gmail.com, pgsql-bugs@lists.postgresql.org Date: Sat, 07 Nov 2026 01:23:41 +0000 Message-ID: <19839-ead02c2208a3f8bd@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19839 Logged by: Atish Prakash Email address: 125atishprak@gmail.com PostgreSQL version: 18.6 Operating system: Linux x86_64 (kernel 7.0.0, glibc 2.43) Description: =20 On an assert-enabled build, logical decoding can fail this assertion and take the server through crash recovery: TRAP: failed Assert("XLogRecPtrIsValid(txn->final_lsn)"), File: "reorderbuffer.c", Line: 5001 Expected: decoding discards the aborted transaction and continues. The sequence is: 1. A transaction has a subtransaction with an XID but no decoded changes, for example one that only ran SELECT ... FOR UPDATE. 2. The parent exceeds logical_decoding_work_mem while still in progress. ReorderBufferSerializeTXN() recurses into the subtransaction, writes nothing, and still sets RBTXN_IS_SERIALIZED on it. Its final_lsn stays invalid. 3. The parent aborts while the decoder is behind. 4. The parent is chosen for eviction before its abort record is decoded. ReorderBufferCheckAndTruncateAbortedTXN() finds it aborted and truncates it, and ReorderBufferRestoreCleanup() fails on the subtransaction's final_lsn. ReorderBufferCheckAndTruncateAbortedTXN() came in with 072ee847ad, so I expect 17 and earlier are not affected, but I have not tested them. From reading the code, a non-assert build goes through an empty cleanup loop for this subtransaction, so I expect no user-visible effect there. I have not run a non-assert build. I found this with a stress test of REPACK (CONCURRENTLY), where the REPACK decoding worker failed in the same way, on both a plain assert build and an ASan build. It does not need REPACK: the attached script uses only pg_recvlogical. It stalls pg_recvlogical with SIGSTOP so that the decoder is behind when the transaction aborts. Proposed fix, attached as 0001-fix-aborted-spilled-txn-assert.patch: set RBTXN_IS_SERIALIZED only if something was written. With the patch, on master: - the script no longer fails - all test_decoding tests and all 239 core regression tests pass - a spilled transaction with an empty subtransaction, a rolled-back subtransaction and a released one decodes the expected rows TAP tests were not run, because my build has them disabled. The patch has no regression test, because the script depends on stalling a live consumer. It applies cleanly to REL_18_STABLE and REL_19_STABLE, but I only built and tested it on master. I found this with a fuzzer, and AI tools helped me build it, write the script and patch, and draft this report. Versions where the script fails: - 18.6 (REL_18_STABLE at 813a74bc5a; the assertion reads txn->final_lsn !=3D InvalidXLogRecPtr) - 19rc1 (REL_19_STABLE at 0b1eb8b917) - master at 72b9498df9, plus my unrelated uncommitted patch to ruleutils.c The patch was built on master at b58a9a97fe. Platform: Linux 7.0.0-42-generic x86_64, glibc 2.43, Intel i9-13900HX, 14 GiB RAM Build: clang 21.1.8, CFLAGS=3D-O1 -g, --enable-cassert --enable-debug --without-icu --without-readline --without-libxml --without-openssl Settings set by the script: wal_level=3Dlogical, logical_decoding_work_mem=3D64kB Stack from 19rc1, with addr2line for the static functions: ReorderBufferRestoreCleanup reorderbuffer.c:5001 ReorderBufferTruncateTXN reorderbuffer.c:1749 (subtransaction) ReorderBufferTruncateTXN reorderbuffer.c:1665 (parent) ReorderBufferCheckAndTruncateAbortedTXN reorderbuffer.c:1819 ReorderBufferQueueChange DecodeInsert decode.c:956 LogicalDecodingProcessRecord Reproducer, run as: logical-decoding-assert-repro.sh #!/bin/bash # Usage: logical-decoding-assert-repro.sh [work dir] # Assertion failure in ReorderBufferRestoreCleanup during logical decoding, without REPACK. set -u BIN=3D$1; WORK=3D${2:-$(mktemp -d)}; PORT=3D${PORT:-6399}; D=3D$WORK/data; = rm -rf "$D"; mkdir -p "$WORK" export PGHOST=3D$WORK PGPORT=3D$PORT PGDATABASE=3Dpostgres "$BIN/initdb" -D "$D" -A trust --no-sync >/dev/null cat >> "$D/postgresql.conf" </dev/null P=3D"$BIN/psql -X -q -v ON_ERROR_STOP=3D1" $P -c "CREATE TABLE t (a text)" -c "INSERT INTO t VALUES ('locked')" \ -c "SELECT pg_create_logical_replication_slot('s', 'test_decoding')" >/dev/null "$BIN/pg_recvlogical" -d postgres -S s --start -f /dev/null -F 0 -s 1 & RECV=3D$! # Session A stays open throughout. FIFO=3D$WORK/a.fifo; rm -f "$FIFO"; mkfifo "$FIFO"; $P < "$FIFO" > /dev/nul= l & APSQL=3D$!; exec 9> "$FIFO" # A: a subtransaction with an XID but no decoded change, then enough to exceed the limit. cat >&9 <&9 sleep 0.5 $P <&9 exec 9>&- wait $APSQL kill -CONT $RECV # decoding resumes; A's abort record has not been read but CLOG says aborted sleep 8 wait $DS 2>/dev/null kill $RECV 2>/dev/null echo "--- server log" grep -E 'TRAP|terminated by signal|was terminated' "$WORK/server.log" | cut -c1-200 "$BIN/pg_ctl" -D "$D" -m immediate stop >/dev/null 2>&1