pgsql: Fix crash with RemoveFromWaitQueue() when detecting a deadlock.

From: Masahiko Sawada <msawada(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix crash with RemoveFromWaitQueue() when detecting a deadlock.
Date: 2023-07-26 05:43:50
Message-ID: E1qOXJN-001Ny4-1H@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/b4f14d2e433bf9f2499f07bcaca07b9ff13d641b

Modified Files
--------------
src/backend/storage/lmgr/lock.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Masahiko Sawada 2023-07-26 05:43:57 pgsql: Fix crash with RemoveFromWaitQueue() when detecting a deadlock.
Previous Message Michael Paquier 2023-07-26 03:49:44 pgsql: worker_spi: Use term "dynamic" for bgworkers launched with worke