From 8c5def6aeb0252d12dda50a8b28e4fddbf255d2e Mon Sep 17 00:00:00 2001 From: Hayato Kuroda Date: Wed, 7 Oct 2026 15:56:06 +0900 Subject: [PATCH v3 2/4] Preserve an error context before entering an apply loop --- src/backend/replication/logical/applyparallelworker.c | 4 ++-- src/backend/replication/logical/worker.c | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/backend/replication/logical/applyparallelworker.c b/src/backend/replication/logical/applyparallelworker.c index 96bf499e49c..afc19ba16ac 100644 --- a/src/backend/replication/logical/applyparallelworker.c +++ b/src/backend/replication/logical/applyparallelworker.c @@ -1046,8 +1046,8 @@ ProcessParallelApplyMessage(StringInfo msg) edata.context = pstrdup(_("logical replication parallel apply worker")); /* - * Context beyond that should use the error context callbacks - * that were in effect in LogicalRepApplyLoop(). + * Use the callbacks saved before the leader's apply error + * context callback was installed. */ error_context_stack = apply_error_context_stack; diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c index 37b37500213..f12cc464be9 100644 --- a/src/backend/replication/logical/worker.c +++ b/src/backend/replication/logical/worker.c @@ -4081,6 +4081,12 @@ LogicalRepApplyLoop(XLogRecPtr last_received) /* mark as idle, before starting to loop */ pgstat_report_activity(STATE_IDLE, NULL); + /* + * Save the current callbacks so that an error propagated from a parallel + * apply worker does not use this leader's unrelated apply error context. + */ + apply_error_context_stack = error_context_stack; + /* * Push apply error context callback. Fields will be filled while applying * a change. @@ -4088,7 +4094,6 @@ LogicalRepApplyLoop(XLogRecPtr last_received) errcallback.callback = apply_error_callback; errcallback.previous = error_context_stack; error_context_stack = &errcallback; - apply_error_context_stack = error_context_stack; /* This outer loop iterates once per wait. */ for (;;) -- 2.52.0