Fix crash with RemoveFromWaitQueue() when detecting a deadlock.
authorMasahiko Sawada <msawada@postgresql.org>
Wed, 26 Jul 2023 05:41:26 +0000 (14:41 +0900)
committerMasahiko Sawada <msawada@postgresql.org>
Wed, 26 Jul 2023 05:41:26 +0000 (14:41 +0900)
commitbd88404d3cda53810e0b0144713c4b1a1dd965a8
tree2eee2aa3a59c73fb2ec426dd9a0a4bdfa0209602
parentd9eb92c7b122c4cf40e95ec45e88b27b318a2be9
Fix crash with RemoveFromWaitQueue() when detecting a deadlock.

Commit 5764f611e 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
src/backend/storage/lmgr/lock.c