Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w5WMz-003KkC-1p for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Mar 2026 22:06:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w5WMw-00GvAr-2m for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Mar 2026 22:06:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w5WMw-00GvAj-1q for pgsql-hackers@lists.postgresql.org; Wed, 25 Mar 2026 22:06:30 +0000 Received: from mail-oo1-xc31.google.com ([2607:f8b0:4864:20::c31]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w5WMu-000000018xm-10yg for pgsql-hackers@lists.postgresql.org; Wed, 25 Mar 2026 22:06:30 +0000 Received: by mail-oo1-xc31.google.com with SMTP id 006d021491bc7-679b072ed3aso243497eaf.1 for ; Wed, 25 Mar 2026 15:06:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774476386; cv=none; d=google.com; s=arc-20240605; b=fO/ATuiofxaq39cd4TNUQw9UKyjYDCWSk8rOdxJ9O6aFbhOaT/sm7nzOVE2Hf83NOZ 2RNMHlPcmojjJEmHDPopYNTfh2Ny9pXtIdhSXS0tWaztgAzpeDlO1a+o3IQua4jobt3q Efw1GuCpcW+EeF3C595eYrrYHYiW6wTBWDNhBfTTXJyiYeyMl6PxphaYNERpYyRo4I69 M8eqjtpgbT9vRkHJr1CD2PWkHJHjWHNvUA90Kzyb+GEIrJyjLs5RBtysp8VBhRaswXWR m6jbE7pWbq62v6L4J8EZ14WcIgz0lqwpDxMnM7+RlxeebK24BgRDyXjqFsg45MOgsNP1 Tn+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=kZv9/+TxnsdKqNqmPV5UYCx5pqAWCs9vlW5TEKgaIRI=; fh=PDhzRmLFhJQgKl2kpY6iqaoiggk+rKjB8rXL7ERgOws=; b=aN6Uu4uXzua3Tc7E2FMcst9/Nt05ifvTV7S3yOOEBzePhuHapmANYkFD2RuE/HoZZE rVZKsJEQWmxkTAd8amvWRTRDSWwWh1ebmmfXNZ1BOCOWvy5sga9Ro4RAAIgKmpZAmxB7 XiNDNdgbeAAEwVP1vOX8OOC3UZWG3dlkrKnb2ic/krJ3iAlcIw7eIOFt7eGRXeg1fXSY dctFomM2D6TPGXMdHUkWPww8sQ0ZL8zZQ4R4l5rDOFq4R1FcWr9F2MiJUUgBmf4HoSu3 qo4k0gflFD+sYRto2c80uZzgGXmn1bOSWBaJNdgQERN7pSuhOSr+ezVZRwzAtde8xXvk AdvQ==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774476386; x=1775081186; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=kZv9/+TxnsdKqNqmPV5UYCx5pqAWCs9vlW5TEKgaIRI=; b=gO7xqbZ6l2zOWqPOkSxoFvAr4elEnzU4OecPC+LSbA62bDsDywO+ErOb441jhpgCwS YrAUUZHqGSWeICJUEbAeqvoqtzyHeBz+oMrlMVvishOk6DcXhKeyI/s83VfJlUbjfKcO UHt0UOnlBg7V5YNWVQGIprgLwn6vTF/6eoxEA+zdDsLBrMqkfKp/ulvhiIki06gA9eUv a/uL6XVKuI00Cn+vqbC+3ZhxEXwkgUm7wTXiAeWYUzBtgDtSow4/19W7ihFcf2ze9zyB Em62WPLrjsF6zN2U3b8yGu/Ezw0b1g+5W0focrEbkWszugN0R4G5BTvD11CBog6cyElM JgaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774476386; x=1775081186; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=kZv9/+TxnsdKqNqmPV5UYCx5pqAWCs9vlW5TEKgaIRI=; b=lriggQUwxgMDksrcwP/LibZ8Pe1MjqDubECCeqPEdUCjXQYIcuDKykR+MMFO0vm4Tv 67qHGhfcFGAjih0qi5o10IPPup0akIQavVuznSsOiAEeyC77yUr5jToPoIccCMPjgIIY dyXq1MLET259PpSlUHAHQemZdGcBRhLnZYQZZReCzh9BZP8Xdna5yYdgDGTRZ1rNY8I+ CkhVVy2jLx+heKP23A22Lqbbra/bQm0OemKt9rwEqaYP0rbpp8GQ0WSotaBuggJjz+Lf gG4JBVbmxr0RWwLCS8hf93yU0K53PsbnU6orhfVLo6qtGqJR74wIfAwY0CNUwwtBwo6u 6duw== X-Gm-Message-State: AOJu0YzQWRrVVx9mu988Hf3BRdT8xK4Nz5wKu4OJz3PsJ4aKKlaxu58s 7W+1mFp3QXoMTrFQbC8Jm2sPYQRn24NZA7GdK3Mf8sHDkfpuaA+Uoey8SsM8xADVstPvM1pU73M kAgFdriiBwKsG5bPk0LvbCDkvdupMcEI= X-Gm-Gg: ATEYQzyd2eDIeO1yds/sUFZfWLvtTLeagZ5FCG9tm4LUPP/GeRsgNifnV48zbfhSXr6 jw5Ks98BIdIWpK2IGFFuA11cUVAE/HUwkhtzt39bYL7f/dpxd+6NAZsPJpzwzkIQ+hE/ytO/xbW eeC7o3ePynNwUm59rIMv7STm/XkjLobvDvbDSHBVr2GYjGsLlt1mGQvwbRNBUmdx/VCy2HMDPTW zwnvrWQzZx+r944SobBjfpTQ5Utkwv5RHqsrPm6fjKm1vKzRRmZjdbawn1RKMaMibalnCnkbuoA HJUWPVeOQOLYLS8v X-Received: by 2002:a05:6820:4b17:b0:67d:6597:4d42 with SMTP id 006d021491bc7-67dff55e5f5mr2992660eaf.50.1774476386610; Wed, 25 Mar 2026 15:06:26 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Bharath Rupireddy Date: Wed, 25 Mar 2026 15:06:14 -0700 X-Gm-Features: AQROBzA3OcRmEnDWIXP1DZGSQ4-ciwoEZSeS21kY_-jWb0vi6YPJoJaEou2UPDs Message-ID: Subject: Re: LockHasWaiters() crashes on fast-path locks To: SATYANARAYANA NARLAPURAM Cc: PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Wed, Mar 25, 2026 at 2:15=E2=80=AFPM SATYANARAYANA NARLAPURAM wrote: > > Hi Hackers, > > LockHasWaiters() assumes that the LOCALLOCK's lock and proclock pointers = are populated, but this is not the case for locks acquired via the fast-pat= h optimization. Weak locks (< ShareUpdateExclusiveLock) on relations may no= t be stored in the shared lock hash table, and the LOCALLOCK entry is left = with lock =3D NULL and proclock =3D NULL in such a case. > > If LockHasWaiters() is called for such a lock, it dereferences those NULL= pointers when it reads proclock->holdMask and lock->waitMask, causing a se= gfault. > > The only existing caller is lazy_truncate_heap() in VACUUM, which queries= LockHasWaitersRelation(rel, AccessExclusiveLock). Since AccessExclusiveLoc= k is the strongest lock level, it is never fast-pathed, so the bug has neve= r been triggered in practice. However, any new caller that passes a weak lo= ck mode, for example, checking whether a DDL is waiting on an AccessShareLo= ck will crash. The fix is to transfer the lock to the main lock table befor= e we access them. > > Attached a patch to address this issue. Nice find! It would be good to add a test case (perhaps in an existing test extension even though we may not commit it; it can act as a demo). I see that this type of lock transfer is happening for prepared statements (see AtPrepare_Locks [1]). However, I see the proposed patch relying on lock =3D=3D NULL for detecting whether the lock was acquired using fast-path. Although this looks correct because if the lock or proclock pointers are NULL, this identifies that the lock was taken using fast-path. But for consistency purposes, can we have the same check as that of AtPrepare_Locks? [1] /* * If the local lock was taken via the fast-path, we need to move it * to the primary lock table, or just get a pointer to the existing * primary lock table entry if by chance it's already been * transferred. */ if (locallock->proclock =3D=3D NULL) -- Bharath Rupireddy Amazon Web Services: https://aws.amazon.com