Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kpXnT-00020D-Gp for pgsql-hackers@arkaria.postgresql.org; Wed, 16 Dec 2020 14:28:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kpXnQ-0004F2-Ie for pgsql-hackers@arkaria.postgresql.org; Wed, 16 Dec 2020 14:28:52 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kpXnQ-0004EB-5O for pgsql-hackers@lists.postgresql.org; Wed, 16 Dec 2020 14:28:52 +0000 Received: from smtp-fw-6002.amazon.com ([52.95.49.90]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kpXnN-0005D2-I6 for pgsql-hackers@postgresql.org; Wed, 16 Dec 2020 14:28:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1608128930; x=1639664930; h=to:cc:references:from:message-id:date:mime-version: in-reply-to:subject; bh=gUzWh0SrNgXNYMFYdBv1NRM4L9T3VKc81z7MtliAq5w=; b=cE+Nj6d0RL//UO+sCBOdcagu4ZHxjhxsQ2WYqOd3+JpcklEnruc+kzVO 738+iMjI2lkdLMP4eg7rSUYOLaroh6kyspHa7/Al/+2pNfBgOeW4McohQ COgXeMiVNAOFGU1EqZYaxu2ErHswhfmlotWepZJ0aOC2daaZKzTVQWNVm A=; X-IronPort-AV: E=Sophos;i="5.78,424,1599523200"; d="scan'208,217";a="71624180" Subject: Re: Deadlock between backend and recovery may not be detected Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-1a-7d76a15f.us-east-1.amazon.com) ([10.43.8.2]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP; 16 Dec 2020 14:28:41 +0000 Received: from EX13D03EUC003.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-1a-7d76a15f.us-east-1.amazon.com (Postfix) with ESMTPS id 6E639A1882; Wed, 16 Dec 2020 14:28:40 +0000 (UTC) Received: from 38f9d36c4abb.ant.amazon.com (10.43.161.184) by EX13D03EUC003.ant.amazon.com (10.43.164.192) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 16 Dec 2020 14:28:37 +0000 To: Victor Yegorov , Fujii Masao CC: PostgreSQL Hackers References: <4041d6b6-cf24-a120-36fa-1294220f8243@oss.nttdata.com> From: "Drouvot, Bertrand" Message-ID: Date: Wed, 16 Dec 2020 15:28:33 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:78.0) Gecko/20100101 Thunderbird/78.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------45D1FB76C407981E627A1F94" Content-Language: en-US X-Originating-IP: [10.43.161.184] X-ClientProxiedBy: EX13D29UWA003.ant.amazon.com (10.43.160.253) To EX13D03EUC003.ant.amazon.com (10.43.164.192) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --------------45D1FB76C407981E627A1F94 Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit Hi, On 12/16/20 2:36 PM, Victor Yegorov wrote: > > *CAUTION*: This email originated from outside of the organization. Do > not click links or open attachments unless you can confirm the sender > and know the content is safe. > > > ср, 16 дек. 2020 г. в 13:49, Fujii Masao >: > > After doing this procedure, you can see the startup process and > backend > wait for the table lock each other, i.e., deadlock. But this > deadlock remains > even after deadlock_timeout passes. > > This seems a bug to me. > +1 > > > * Deadlocks involving the Startup process and an ordinary > backend process > > * will be detected by the deadlock detector within the ordinary > backend. > > The cause of this issue seems that > ResolveRecoveryConflictWithLock() that > the startup process calls when recovery conflict on lock happens > doesn't > take care of deadlock case at all. You can see this fact by > reading the above > source code comment for ResolveRecoveryConflictWithLock(). > > To fix this issue, I think that we should enable > STANDBY_DEADLOCK_TIMEOUT > timer in ResolveRecoveryConflictWithLock() so that the startup > process can > send PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK signal to the backend. > Then if PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK signal arrives, > the backend should check whether the deadlock actually happens or not. > Attached is the POC patch implimenting this. > good catch! I don't see any obvious reasons why the STANDBY_DEADLOCK_TIMEOUT shouldn't be set in ResolveRecoveryConflictWithLock() too (it is already set in ResolveRecoveryConflictWithBufferPin()). So + 1 to consider this as a bug and for the way the patch proposes to fix it. Bertrand --------------45D1FB76C407981E627A1F94 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: 8bit

Hi,

On 12/16/20 2:36 PM, Victor Yegorov wrote:

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.


ср, 16 дек. 2020 г. в 13:49, Fujii Masao <masao.fujii@oss.nttdata.com>:
After doing this procedure, you can see the startup process and backend
wait for the table lock each other, i.e., deadlock. But this deadlock remains
even after deadlock_timeout passes.

This seems a bug to me.

+1


> * Deadlocks involving the Startup process and an ordinary backend process
> * will be detected by the deadlock detector within the ordinary backend.

The cause of this issue seems that ResolveRecoveryConflictWithLock() that
the startup process calls when recovery conflict on lock happens doesn't
take care of deadlock case at all. You can see this fact by reading the above
source code comment for ResolveRecoveryConflictWithLock().

To fix this issue, I think that we should enable STANDBY_DEADLOCK_TIMEOUT
timer in ResolveRecoveryConflictWithLock() so that the startup process can
send PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK signal to the backend.
Then if PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK signal arrives,
the backend should check whether the deadlock actually happens or not.
Attached is the POC patch implimenting this.

good catch!

I don't see any obvious reasons why the STANDBY_DEADLOCK_TIMEOUT shouldn't be set in ResolveRecoveryConflictWithLock() too (it is already set in ResolveRecoveryConflictWithBufferPin()).

So + 1 to consider this as a bug and for the way the patch proposes to fix it.

Bertrand
--------------45D1FB76C407981E627A1F94--