Skip to content

Commit

Permalink
Fix crash with RemoveFromWaitQueue() when detecting a deadlock.
Browse files Browse the repository at this point in the history
Commit 5764f61 used dclist_delete_from() to remove the proc from the
wait queue. However, since it doesn't clear dist_node's next/prev to
NULL, it could call RemoveFromWaitQueue() twice: when the process
detects a deadlock and then when cleaning up locks on aborting the
transaction. The waiting lock information is cleared in the first
call, so it led to a crash in the second call.

Backpatch to v16, where the change was introduced.

Bug: #18031
Reported-by: Justin Pryzby, Alexander Lakhin
Reviewed-by: Andres Freund
Discussion: https://postgr.es/m/ZKy4AdrLEfbqrxGJ%40telsasoft.com
Discussion: https://postgr.es/m/18031-ebe2d08cb405f6cc@postgresql.org
Backpatch-through: 16
  • Loading branch information
MasahikoSawada committed Jul 26, 2023
1 parent d9eb92c commit bd88404
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/backend/storage/lmgr/lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1881,7 +1881,7 @@ RemoveFromWaitQueue(PGPROC *proc, uint32 hashcode)
Assert(0 < lockmethodid && lockmethodid < lengthof(LockMethods));

/* Remove proc from lock's wait queue */
dclist_delete_from(&waitLock->waitProcs, &proc->links);
dclist_delete_from_thoroughly(&waitLock->waitProcs, &proc->links);

/* Undo increments of request counts by waiting process */
Assert(waitLock->nRequested > 0);
Expand Down

0 comments on commit bd88404

Please sign in to comment.