Skip to content
Open
18 changes: 18 additions & 0 deletions pglogical_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

#include "storage/ipc.h"
#include "storage/latch.h"
#include "storage/lmgr.h"
#include "storage/proc.h"

#include "tcop/tcopprot.h"
Expand Down Expand Up @@ -600,6 +601,23 @@ pglogical_drop_subscription(PG_FUNCTION_ARGS)
LWLockRelease(PGLogicalCtx->lock);
break;
}

if (apply->proc->waitLock)
{
const LOCKTAG apply_lock_tag = apply->proc->waitLock->tag;
if (((LockTagType) apply_lock_tag.locktag_type == LOCKTAG_TRANSACTION) &&

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check works only for 2 processes deadlock cycle (apply worker and drop sub process).
PostgreSQL deadlock detection ( DeadLockCheck(PGPROC *proc) ) is not working here because drop subscription worker do not locked by apply worker, it just waiting for apply being stopped.

(apply_lock_tag.locktag_field1 == (uint32)GetCurrentTransactionId()))
{
StringInfoData buf;
initStringInfo(&buf);
DescribeLockTag(&buf, &apply_lock_tag);
elog( WARNING, "Apply worker [%d] is locked by %s of [%d], try to kill it", apply->proc->pid, buf.data, MyProc->pid );

/* cancel transaction */
kill(apply->proc->pid, SIGINT);
}
}

LWLockRelease(PGLogicalCtx->lock);

CHECK_FOR_INTERRUPTS();
Expand Down