Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix deadlock during waiting for apply worker stop (issue #258) #260

Open
wants to merge 11 commits into
base: REL2_x_STABLE
Choose a base branch
from
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
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