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 1hcHSK-0008Ve-UR for pgsql-hackers@arkaria.postgresql.org; Sat, 15 Jun 2019 22:47:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hcHSI-0004AH-Lr for pgsql-hackers@arkaria.postgresql.org; Sat, 15 Jun 2019 22:47:26 +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 1hcHSI-0004AA-5M for pgsql-hackers@lists.postgresql.org; Sat, 15 Jun 2019 22:47:26 +0000 Received: from mail-qk1-x741.google.com ([2607:f8b0:4864:20::741]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hcHSA-0007K9-FV for pgsql-hackers@lists.postgresql.org; Sat, 15 Jun 2019 22:47:24 +0000 Received: by mail-qk1-x741.google.com with SMTP id g18so4052416qkl.3 for ; Sat, 15 Jun 2019 15:47:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=cle5HDg5IeOa1qc+Cp6dfCZxGz80u33P9wjfEToDgqw=; b=OtVNYghikSrWnIRELpXkzvljYnyOnYJYKKeWeZu14q5RdqePWSgB2F2UhnW5Bj7Pay nbH2pHLJP9ZrfsYlFlZobOIw/OfcYbA0B7CPOEIJo3mAX1tYBHvNQb7/dZPSnYASY3o6 Su+eLgRH5Agw3iOvSY3PR6JPFJaIuoUa3Xz0aXpSsA4NNedX0gx23+ZwZsYLUy0oF73A f0YdrLeWao7G3QQIvROFiv+LsfLebj0kjb1ggGUULa4p84lR/EmIUnX1KgF5Yb2QMJ0A YKEDiPTI7XViZ80e6H+peNXI2zscScoFN7VSZHdK4z6SIheMWSyX4EdyC8+1KydfWJsY C8Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=cle5HDg5IeOa1qc+Cp6dfCZxGz80u33P9wjfEToDgqw=; b=c7yq24JENEfCsLzmQnJre3pY486IKfmq9pK85Gp13aKsNNlQEc0iJD3ivjIA6E3veR svW0F2KhHpMN92SO0u3QP8PFDq31yiK8bU090Sbo5FfTLB5mD913kF3Xe7tOjAbIBcHX TEvJDUIqEEzhyHSlFKrhmuTcRvvWpnNB7git6WRFuZGSFDNTx5pDsUJnBc1zgZRbDDH6 yuexnVTBBOmBDDWYUkmH9eFjJvbsSuRM4UJ1eGTEYkSr7/0I9WjENVysnyzF7eEcSPq0 EvJhZNWEbiRk/msKx6n5Pj59NHv1qHfgHDqXn5+4fiuKh8RaVtFNloVhDJsJOefWyxrq EC0A== X-Gm-Message-State: APjAAAUu9B51LyIEFQdZOkaaCkdPGbYOuNLm5loIokOJP0TG+2qggRnc 6DmosE49xBbhTjSVUF+j4tKE+A== X-Google-Smtp-Source: APXvYqzwRqbwgJm9UPXgQLRp44dO0oPl2oP05g7D5yrwguvpFmAvhxhXcxRsqm5CWPrTfUfYGprOtg== X-Received: by 2002:a37:d16:: with SMTP id 22mr63688958qkn.232.1560638837529; Sat, 15 Jun 2019 15:47:17 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([177.154.139.203]) by smtp.gmail.com with ESMTPSA id s125sm2690831qkc.43.2019.06.15.15.47.16 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 15 Jun 2019 15:47:17 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id E4581120AF4; Sat, 15 Jun 2019 18:47:13 -0400 (-04) Date: Sat, 15 Jun 2019 18:47:13 -0400 From: Alvaro Herrera To: Oleksii Kliukin Cc: Tom Lane , pgsql-hackers@lists.postgresql.org Subject: Re: pgsql: Avoid spurious deadlocks when upgrading a tuple lock Message-ID: <20190615224713.GA9414@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <5EF8408A-46E6-409A-96A7-DC2C27F36235@hintbits.com> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2019-Jun-16, Oleksii Kliukin wrote: > Alvaro Herrera wrote: > > > On 2019-Jun-14, Alvaro Herrera wrote: > > > >> 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.) > > > > 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. > > > > I'm still trying to form a case to exercise the case of skip_tuple_lock > > having the wrong lifetime. > > Hm… 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. 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. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services