agora inbox for pgsql-hackers@postgresql.orghelp / color / mirror / Atom feed
[PATCH 3/5] WIP: Add SKIPVALID flag for more integration 295+ messages / 2 participants [nested] [flat]
* [PATCH 3/5] WIP: Add SKIPVALID flag for more integration @ 2020-10-30 21:23 Justin Pryzby <pryzbyj@telsasoft.com> 0 siblings, 0 replies; 295+ messages in thread From: Justin Pryzby @ 2020-10-30 21:23 UTC (permalink / raw) XXX: this breaks progress reporting? --- src/backend/commands/indexcmds.c | 36 +++++++++++++++----------------- src/include/catalog/index.h | 1 + 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 8f4eab22eb..e54314e9a4 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -1637,40 +1637,33 @@ DefineIndex(Oid relationId, return address; } -/* Reindex invalid child indexes created earlier */ +/* + * Reindex invalid child indexes created earlier thereby validating + * the parent index. + */ static void reindex_invalid_child_indexes(Oid indexRelationId) { - ListCell *lc; - int npart = 0; ReindexParams params = { - .options = REINDEXOPT_CONCURRENTLY + .options = REINDEXOPT_CONCURRENTLY | REINDEXOPT_SKIPVALID }; - PreventInTransactionBlock(true, "REINDEX INDEX"); - - foreach (lc, find_inheritance_children(indexRelationId, ShareLock)) - { - Oid partoid = lfirst_oid(lc); - - if (!get_index_isvalid(partoid) && - RELKIND_HAS_STORAGE(get_rel_relkind(partoid))) - ReindexRelationConcurrently(partoid, ¶ms); - - pgstat_progress_update_param(PROGRESS_CREATEIDX_PARTITIONS_DONE, - npart++); - } - /* * CIC needs to mark a partitioned index as VALID, which itself * requires setting READY, which is unset for CIC (even though * it's meaningless for an index without storage). * This must be done only while holding a lock which precludes adding * partitions. - * See also: validatePartitionedIndex(). */ CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_READY); + + /* + * Process each partition listed in a separate transaction. Note that + * this commits and then starts a new transaction immediately. + */ + ReindexPartitions(indexRelationId, ¶ms, true); + CommandCounterIncrement(); index_set_state_flags(indexRelationId, INDEX_CREATE_SET_VALID); } @@ -3094,6 +3087,11 @@ ReindexPartitions(Oid relid, ReindexParams *params, bool isTopLevel) if (!RELKIND_HAS_STORAGE(partkind)) continue; + /* Skip valid indexes, if requested */ + if ((params->options & REINDEXOPT_SKIPVALID) != 0 && + get_index_isvalid(partoid)) + continue; + Assert(partkind == RELKIND_INDEX || partkind == RELKIND_RELATION); diff --git a/src/include/catalog/index.h b/src/include/catalog/index.h index e22d506436..994fe94fa1 100644 --- a/src/include/catalog/index.h +++ b/src/include/catalog/index.h @@ -42,6 +42,7 @@ typedef struct ReindexParams #define REINDEXOPT_REPORT_PROGRESS 0x02 /* report pgstat progress */ #define REINDEXOPT_MISSING_OK 0x04 /* skip missing relations */ #define REINDEXOPT_CONCURRENTLY 0x08 /* concurrent mode */ +#define REINDEXOPT_SKIPVALID 0x10 /* skip valid indexes */ /* state info for validate_index bulkdelete callback */ typedef struct ValidateIndexState -- 2.17.0 --dTy3Mrz/UPE2dbVg Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0004-ReindexPartitions-to-set-indisvalid.patch" ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
* [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. @ 2025-09-03 09:33 Antonin Houska <ah@cybertec.at> 0 siblings, 0 replies; 295+ messages in thread From: Antonin Houska @ 2025-09-03 09:33 UTC (permalink / raw) Users of logical decoding can encounter unexpected change of CurrentResourceOwner and CurrentMemoryContext. The problem is that in reorderbuffer.c, unlike other call sites, we call RollbackAndReleaseCurrentSubTransaction() without restoring the original values of these global variables. This patch saves the values prior to the call and restores them eventually. --- src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 34cf05668ae..4736f993c37 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2215,6 +2215,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, { bool using_subtxn; MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; ReorderBufferIterTXNState *volatile iterstate = NULL; volatile XLogRecPtr prev_lsn = InvalidXLogRecPtr; ReorderBufferChange *volatile specinsert = NULL; @@ -2692,7 +2693,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * We are here due to one of the four reasons: 1. Decoding an @@ -2751,7 +2756,11 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, } if (using_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } /* * The error code ERRCODE_TRANSACTION_ROLLBACK indicates a concurrent @@ -3244,6 +3253,8 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations) { bool use_subtxn = IsTransactionOrTransactionBlock(); + MemoryContext ccxt = CurrentMemoryContext; + ResourceOwner cowner = CurrentResourceOwner; int i; if (use_subtxn) @@ -3262,7 +3273,11 @@ ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, LocalExecuteInvalidationMessage(&invalidations[i]); if (use_subtxn) + { RollbackAndReleaseCurrentSubTransaction(); + MemoryContextSwitchTo(ccxt); + CurrentResourceOwner = cowner; + } } /* -- 2.47.1 --=-=-=-- ^ permalink raw reply [nested|flat] 295+ messages in thread
end of thread, other threads:[~2025-09-03 09:33 UTC | newest] Thread overview: 295+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2020-10-30 21:23 [PATCH 3/5] WIP: Add SKIPVALID flag for more integration Justin Pryzby <pryzbyj@telsasoft.com> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox