Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdIcY-0006iz-Ej for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Jun 2019 18:14:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hdIcW-00082R-Sk for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Jun 2019 18:14:12 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdIcW-00082K-E7 for pgsql-hackers@lists.postgresql.org; Tue, 18 Jun 2019 18:14:12 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdIcT-0006zf-Ax for pgsql-hackers@lists.postgresql.org; Tue, 18 Jun 2019 18:14:11 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 4D577662; Tue, 18 Jun 2019 14:14:07 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Tue, 18 Jun 2019 14:14:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hintbits.com; h= content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; s=mesmtp; bh=p95XTAhh6JyRghRSruD4fOz1eRjZ91hMT01VqOkABBk=; b=HgD+jqbGMOnL tZO6yB+DkNSQPjYBezxHmzSy6A1nxC9JNjd+ry5u+YczhhSJax1vO5hTkD7c00HY SkpWuWh0dMRLZQt5T85p/jXQEMHgs838axOwnK7T3bJMerv6i6xjNykbpzw9811x 0SRpKrtHBe/4we49xL//R/E31ThGM+s= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=p95XTAhh6JyRghRSruD4fOz1eRjZ91hMT01VqOkAB Bk=; b=y2P/GzbO/Z+Gbq2Mdn9KS4Y/tVEYaVY2NZr/gJhgNqPmSq6thflsjyj8h /AU6UmRFnHNntD8SsjBe8w2DIVZqra9/c0vzbuO+7Fps2Tyzhb2yR68L5OIMcbqx ZcqZSduWuP5J9lyTkWVMI0ynZe8sqo5UuIwq654i2ei1kEODM1sPqKeANuIhty8g YejUdWTYY6EB16QEYf5HOIa+XoY38891wDV7ULxbEjBXU/PEokJhY6hXbbutu3gB sFi5xvMOB48MtrInjF9s7x5ajIxL6cE1aRgCKRbaoPBOBuX/ZVW6AiI3SjWQSDKh 7EoqpBuzh7Ali69u/lU0LTUVsCNeg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrtddtgdelfecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurheptggguffhjgffgffkfhfvofesthhqmh dthhdtjeenucfhrhhomhepqfhlvghkshhiihcumfhlihhukhhinhcuoegrlhgvgihksehh ihhnthgsihhtshdrtghomheqnecuffhomhgrihhnpehpohhsthhgrhgvshhqlhdrohhrgh enucfkphepudelfedruddviedrvdegjedrudelleenucfrrghrrghmpehmrghilhhfrhho mheprghlvgigkheshhhinhhtsghithhsrdgtohhmnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from [192.168.92.147] (193-126-247-199.net.novis.pt [193.126.247.199]) by mail.messagingengine.com (Postfix) with ESMTPA id 563778005A; Tue, 18 Jun 2019 14:14:05 -0400 (EDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: Re: pgsql: Avoid spurious deadlocks when upgrading a tuple lock From: Oleksii Kliukin In-Reply-To: <20190615224713.GA9414@alvherre.pgsql> Date: Tue, 18 Jun 2019 19:13:49 +0100 Cc: Tom Lane , pgsql-hackers@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <20190615224713.GA9414@alvherre.pgsql> To: =?utf-8?Q?=C3=81lvaro_Herrera?= X-Mailer: Apple Mail (2.3445.104.11) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Alvaro Herrera wrote: > On 2019-Jun-16, Oleksii Kliukin wrote: >=20 >> Alvaro Herrera wrote: >>=20 >>> On 2019-Jun-14, Alvaro Herrera wrote: >>>=20 >>>> I think there are worse problems here. I tried the attached = isolation >>>> spec. Note that the only difference in the two permutations is = that s0 >>>> finishes earlier in one than the other; yet the first one works = fine and >>>> the second one hangs until killed by the 180s timeout. (s3 isn't >>>> released for a reason I'm not sure I understand.) >>>=20 >>> Actually, those behaviors both seem correct to me now that I look >>> closer. So this was a false alarm. In the code before de87a084c0, = the >>> first permutation deadlocks, and the second permutation hangs. The = only >>> behavior change is that the first one no longer deadlocks, which is = the >>> desired change. >>>=20 >>> I'm still trying to form a case to exercise the case of = skip_tuple_lock >>> having the wrong lifetime. >>=20 >> Hm=E2=80=A6 I think it was an oversight from my part not to give = skip_lock_tuple the >> same lifetime as have_tuple_lock or first_time (also initializing it = to >> false at the same time). Even if now it might not break anything in = an >> obvious way, a backward jump to l3 label will leave skip_lock_tuple >> uninitialized, making it very dangerous for any future code that will = rely >> on its value. >=20 > But that's not the danger ... with the current coding, it's = initialized > to false every time through that block; that means the tuple lock will > never be skipped if we jump back to l3. So the danger is that the = first > iteration sets the variable, then jumps back; second iteration > initializes the variable again, so instead of skipping the lock, it > takes it, causing a spurious deadlock. Sorry, I was confused, as I was looking only at = https://git.postgresql.org/gitweb/?p=3Dpostgresql.git;a=3Dcommitdiff;h=3Dd= e87a084c0a5ac927017cd0834b33a932651cfc9 without taking your subsequent commit that silences compiler warnings at = https://git.postgresql.org/gitweb/?p=3Dpostgresql.git;a=3Dcommitdiff;h=3D3= da73d6839dc47f1f47ca57974bf28e5abd9b572 into consideration. With that commit, the danger is indeed in resetting = the skip mechanism on each jump and potentially causing deadlocks. Cheers, Oleksii=