agora inbox for pgsql-hackers@postgresql.orghelp / color / mirror / Atom feed
[PATCH v9 1/2] instr_time: Add INSTR_TIME_SET_SECONDS(), INSTR_TIME_IS_LT() 295+ messages / 2 participants [nested] [flat]
* [PATCH v9 1/2] instr_time: Add INSTR_TIME_SET_SECONDS(), INSTR_TIME_IS_LT() @ 2023-01-20 23:31 Andres Freund <andres@anarazel.de> 0 siblings, 0 replies; 295+ messages in thread From: Andres Freund @ 2023-01-20 23:31 UTC (permalink / raw) INSTR_TIME_SET_SECONDS() is useful to calculate the end of a time-bound loop without having to convert into time units (which is costly). INSTR_TIME_IS_LT() can be used to check the loop condition. Author: Reviewed-by: Discussion: https://postgr.es/m/ Backpatch: --- src/include/portability/instr_time.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/include/portability/instr_time.h b/src/include/portability/instr_time.h index cc85138e21f..aab80effb00 100644 --- a/src/include/portability/instr_time.h +++ b/src/include/portability/instr_time.h @@ -15,6 +15,8 @@ * * INSTR_TIME_IS_ZERO(t) is t equal to zero? * + * INSTR_TIME_IS_LT(x, y) x < y + * * INSTR_TIME_SET_ZERO(t) set t to zero (memset is acceptable too) * * INSTR_TIME_SET_CURRENT(t) set t to current time @@ -22,6 +24,8 @@ * INSTR_TIME_SET_CURRENT_LAZY(t) set t to current time if t is zero, * evaluates to whether t changed * + * INSTR_TIME_SET_SECONDS(t, s) set t to s seconds + * * INSTR_TIME_ADD(x, y) x += y * * INSTR_TIME_SUBTRACT(x, y) x -= y @@ -122,6 +126,9 @@ pg_clock_gettime_ns(void) #define INSTR_TIME_SET_CURRENT(t) \ ((t) = pg_clock_gettime_ns()) +#define INSTR_TIME_SET_SECONDS(t, s) \ + ((t).ticks = NS_PER_S * (s)) + #define INSTR_TIME_GET_NANOSEC(t) \ ((int64) (t).ticks) @@ -156,6 +163,9 @@ GetTimerFrequency(void) #define INSTR_TIME_SET_CURRENT(t) \ ((t) = pg_query_performance_counter()) +#define INSTR_TIME_SET_SECONDS(t, s) \ + ((t).ticks = s * GetTimerFrequency()) + #define INSTR_TIME_GET_NANOSEC(t) \ ((int64) ((t).ticks * ((double) NS_PER_S / GetTimerFrequency()))) @@ -168,6 +178,8 @@ GetTimerFrequency(void) #define INSTR_TIME_IS_ZERO(t) ((t).ticks == 0) +#define INSTR_TIME_IS_LT(x, y) ((x).ticks < (y).ticks) + #define INSTR_TIME_SET_ZERO(t) ((t).ticks = 0) -- 2.38.0 --2e47imhqa2hvpvyc Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0002-wip-report-nanoseconds-in-pg_test_timing.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 -- 2023-01-20 23:31 [PATCH v9 1/2] instr_time: Add INSTR_TIME_SET_SECONDS(), INSTR_TIME_IS_LT() Andres Freund <andres@anarazel.de> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext. Antonin Houska <ah@cybertec.at> 2025-09-03 09:33 [PATCH] Avoid unexpected changes of CurrentResourceOwner and 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