summaryrefslogtreecommitdiff
path: root/src/backend/replication/logical/worker.c
diff options
context:
space:
mode:
authorAmit Kapila <akapila@postgresql.org>2025-09-09 03:18:22 +0000
committerAmit Kapila <akapila@postgresql.org>2025-09-09 03:18:22 +0000
commit5ac3c1ac22cb325844d0bee37f79f2c11931b32e (patch)
tree3431f286636ff5601bc4e0564c81a10dd4cb28d5 /src/backend/replication/logical/worker.c
parent8ec97e78a7713a1ebf4976b55c19f6c9bc2716d9 (diff)
Fix Coverity issue reported in commit a850be2fe.
Address a potential SIGSEGV that may occur when the tablesync worker attempts to locate a deleted row while applying changes. This situation arises during conflict detection for update-deleted scenarios. To prevent this crash, ensure that the operation is errored out early if the leader apply worker is unavailable. Since the leader worker maintains the necessary conflict detection metadata, proceeding without it serves no purpose and risks reporting incorrect conflict type. In the passing, improve a nearby comment. Reported by Tom Lane as per Coverity Author: shveta malik <shveta.malik@gmail.com> Reviewed-by: Amit Kapila <amit.kapila16@gmail.com> Discussion: https://postgr.es/m/334468.1757280992@sss.pgh.pa.us
Diffstat (limited to 'src/backend/replication/logical/worker.c')
-rw-r--r--src/backend/replication/logical/worker.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c
index c0f6bef5c28..b3cac102373 100644
--- a/src/backend/replication/logical/worker.c
+++ b/src/backend/replication/logical/worker.c
@@ -3266,12 +3266,18 @@ FindDeletedTupleInLocalRel(Relation localrel, Oid localidxoid,
/*
* Obtain the information from the leader apply worker as only the
- * leader manages conflict retention (see
+ * leader manages oldest_nonremovable_xid (see
* maybe_advance_nonremovable_xid() for details).
*/
LWLockAcquire(LogicalRepWorkerLock, LW_SHARED);
leader = logicalrep_worker_find(MyLogicalRepWorker->subid,
InvalidOid, false);
+ if (!leader)
+ {
+ ereport(ERROR,
+ (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+ errmsg("could not detect conflict as the leader apply worker has exited")));
+ }
SpinLockAcquire(&leader->relmutex);
oldestxmin = leader->oldest_nonremovable_xid;