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.94.2) (envelope-from ) id 1tyEKN-00424e-1H for pgsql-hackers@arkaria.postgresql.org; Fri, 28 Mar 2025 18:21:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tyEKL-00EJfB-OM for pgsql-hackers@arkaria.postgresql.org; Fri, 28 Mar 2025 18:21:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tyEKL-00EJdu-BC for pgsql-hackers@lists.postgresql.org; Fri, 28 Mar 2025 18:21:09 +0000 Received: from meesny.iki.fi ([2001:67c:2b0:1c1::201]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tyEKF-001fI7-0W for pgsql-hackers@postgresql.org; Fri, 28 Mar 2025 18:21:08 +0000 Received: from [192.168.1.112] (iptv-hkibng21-58c090-167.dhcp.inet.fi [88.192.144.167]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by meesny.iki.fi (Postfix) with ESMTPSA id 4ZPTNp2LdwzySr; Fri, 28 Mar 2025 20:20:58 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1743186059; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k8xeUQ33wO4d+XnYkNtpxwQV96zKJFJAgVfdXfS9vts=; b=TxeVkzS9l3uKkCquD1XOG/g5gwuW2r51PA8VgS4XfHC/dM8ZoICISvPOOmevJS8Ij5poCb L2yFORzvdzBvcGsYqE2ISxmCdSwLg9lLPHDI3+DFe0aw0IrVDsUaCz76Yzdup+5pKU8vVZ p+TaIUvMeZ8SK8kT0yMiHzbU2zFNKTM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1743186059; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k8xeUQ33wO4d+XnYkNtpxwQV96zKJFJAgVfdXfS9vts=; b=FuKZIbZF0tUkKbRH8WCAllIb5HZ4DaOUsRR9PEi6tZCT6Ed8CXukxUH/ttLi3i6h8b9AZk 4M5p8H7YHMGdGWbMzFHFlr5SUGxGuphhy1QOcTAgvaNGpmSwkn1bBYbQ19x56Dzjqvgej7 1J4NJmwPQ0ib5lACQV1P12JydsAy0NA= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1743186059; a=rsa-sha256; cv=none; b=CoNPS6kyqp7zlZPPFmY7xYnTyZJXWJz1dlgRnpXbka0oTr0bJNtR+OEX/cHndZXuImvdU5 20z2Ii3xCVMwtKV0J0Mwen9lNk7kTmGFkZj/gycB31d+5cVL8YMquNjSFqnVyIbOB/yctS v6xPvhAZRSV07inzCK8nFJcyeL0bW88= Message-ID: <4961142a-7958-4229-8329-8777b4b72690@iki.fi> Date: Fri, 28 Mar 2025 20:20:57 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Latches vs lwlock contention To: Alexander Lakhin , Maxim Orlov Cc: Thomas Munro , pgsql-hackers , Yura Sokolov , Andres Freund References: <53c844e1-a21a-e481-cca5-2184c8aa47b9@iki.fi> <7c2090cd-a72a-4e34-afaa-6dd2ef31440e@iki.fi> Content-Language: en-US From: Heikki Linnakangas In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 27/03/2025 07:00, Alexander Lakhin wrote: > I've discovered that the following script: > export PGOPTIONS='-c lock_timeout=1s' > createdb regression > for i in {1..100}; do > echo "ITERATION: $i" > psql -c "CREATE TABLE t(i int);" > cat << 'EOF' | psql & > DO $$ > DECLARE >     i int; > BEGIN >    FOR i IN 1 .. 5000000 LOOP >     INSERT INTO t VALUES (1); >   END LOOP; > END; > $$; > EOF > sleep 1 > psql -c "DROP TABLE t" & > cat << 'EOF' | psql & > COPY t FROM STDIN; > 0 > \. > EOF > wait > > psql -c "DROP TABLE t" || break; > done > > causes a segmentation fault on master (it fails on iterations 5, 4, 26 > for me): > ITERATION: 26 > CREATE TABLE > ERROR:  canceling statement due to lock timeout > ERROR:  canceling statement due to lock timeout > invalid command \. > ERROR:  syntax error at or near "0" > LINE 1: 0 >         ^ > server closed the connection unexpectedly > > Core was generated by `postgres: law regression [local] > idle                                         '. > Program terminated with signal SIGSEGV, Segmentation fault. > #0  GrantLockLocal (locallock=0x5a1d75c35ba8, owner=0x5a1d75c18630) at > lock.c:1805 > 1805            lockOwners[i].owner = owner; > (gdb) bt > #0  GrantLockLocal (locallock=0x5a1d75c35ba8, owner=0x5a1d75c18630) at > lock.c:1805 > #1  0x00005a1d51e93ee7 in GrantAwaitedLock () at lock.c:1887 > #2  0x00005a1d51ea1e58 in LockErrorCleanup () at proc.c:814 > #3  0x00005a1d51b9a1a7 in AbortTransaction () at xact.c:2853 > #4  0x00005a1d51b9abc6 in AbortCurrentTransactionInternal () at xact.c:3579 > #5  AbortCurrentTransaction () at xact.c:3457 > #6  0x00005a1d51eafeda in PostgresMain (dbname=, > username=0x5a1d75c139b8 "law") at postgres.c:4440 > > (gdb) p lockOwners > $1 = (LOCALLOCKOWNER *) 0x0 > > git bisect led me to 3c0fd64fe. > Could you please take a look? Great, thanks for the repro! With that, I was able to capture the failure with 'rr' and understand what happens: Commit 3c0fd64fe removed "lockAwaited = NULL;" from LockErrorCleanup(). Because of that, if the lock had been granted to us, and if LockErrorCleanup() was called twice, the second call would call GrantAwaitedLock() even if the lock was already released and cleaned up. I've pushed a fix to put that back. -- Heikki Linnakangas Neon (https://neon.tech)