Skip to content

Commit 51a0382

Browse files
committed
Fix crash if LockErrorCleanup() is called twice
The refactoring in commit 3c0fd64 removed the clearing of awaitedLock from LockErrorCleanup(). It's still needed, otherwise LockErrorCleanup() during abort processing will try to update the LOCALLOCK struct even after the lock has already been released. Put it back. Reported-by: Richard Guo <guofenglinux@gmail.com> Reported-by: Robins Tharakan <tharakan@gmail.com> Reported-by: Alexander Lakhin <exclusion@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/CAMbWs4_dNX1SzBmvFdoY-LxJh_4W_BjtVd5i008ihfU-wFF=eg@mail.gmail.com Discussion: https://www.postgresql.org/message-id/18832-38e5575b1bbd7277@postgresql.org Discussion: https://www.postgresql.org/message-id/e11a30e5-c0d8-491d-8546-3a1b50c10ad4@gmail.com
1 parent 9ac6f7e commit 51a0382

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

src/backend/storage/lmgr/lock.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,6 +1896,15 @@ GetAwaitedLock(void)
18961896
return awaitedLock;
18971897
}
18981898

1899+
/*
1900+
* ResetAwaitedLock -- Forget that we are waiting on a lock.
1901+
*/
1902+
void
1903+
ResetAwaitedLock(void)
1904+
{
1905+
awaitedLock = NULL;
1906+
}
1907+
18991908
/*
19001909
* MarkLockClear -- mark an acquired lock as "clear"
19011910
*

src/backend/storage/lmgr/proc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,8 @@ LockErrorCleanup(void)
814814
GrantAwaitedLock();
815815
}
816816

817+
ResetAwaitedLock();
818+
817819
LWLockRelease(partitionLock);
818820

819821
RESUME_INTERRUPTS();

src/include/storage/lock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ extern bool LockCheckConflicts(LockMethod lockMethodTable,
588588
extern void GrantLock(LOCK *lock, PROCLOCK *proclock, LOCKMODE lockmode);
589589
extern void GrantAwaitedLock(void);
590590
extern LOCALLOCK *GetAwaitedLock(void);
591+
extern void ResetAwaitedLock(void);
591592

592593
extern void RemoveFromWaitQueue(PGPROC *proc, uint32 hashcode);
593594
extern LockData *GetLockStatusData(void);

0 commit comments

Comments
 (0)