diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c index ed8a734be7e..b49dfbaeec8 100644 --- a/src/backend/storage/lmgr/lock.c +++ b/src/backend/storage/lmgr/lock.c @@ -1956,6 +1956,7 @@ RemoveFromWaitQueue(PGPROC *proc, uint32 hashcode) proc->waitLock = NULL; proc->waitProcLock = NULL; proc->waitStatus = PROC_WAIT_STATUS_ERROR; + pg_atomic_write_u64(&proc->waitStart, 0); /* * Delete the proclock immediately if it represents no already-held locks. diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 450fb2a71d4..6a98b79bc3c 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -766,6 +766,9 @@ LockErrorCleanup(void) GrantAwaitedLock(); } + /* An error can bypass ProcSleep()'s reset, so clear waitStart here */ + pg_atomic_write_u64(&MyProc->waitStart, 0); + lockAwaited = NULL; LWLockRelease(partitionLock); @@ -1664,6 +1667,12 @@ ProcSleep(LOCALLOCK *locallock, LockMethod lockMethodTable) } } while (myWaitStatus == PROC_WAIT_STATUS_WAITING); + /* + * Clear waitStart after the wait, as we may have set it after + * ProcWakeup() cleared it. + */ + pg_atomic_write_u64(&MyProc->waitStart, 0); + /* * Disable the timers, if they are still running. As in LockErrorCleanup, * we must preserve the LOCK_TIMEOUT indicator flag: if a lock timeout has