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 1pJCAm-00076O-Hb for pgsql-bugs@arkaria.postgresql.org; Sat, 21 Jan 2023 11:36:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pJCAk-0006WM-VG for pgsql-bugs@arkaria.postgresql.org; Sat, 21 Jan 2023 11:36:34 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pJCAk-0006WC-L8 for pgsql-bugs@lists.postgresql.org; Sat, 21 Jan 2023 11:36:34 +0000 Received: from mail-oi1-x234.google.com ([2607:f8b0:4864:20::234]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pJCAe-0008FU-4J for pgsql-bugs@lists.postgresql.org; Sat, 21 Jan 2023 11:36:34 +0000 Received: by mail-oi1-x234.google.com with SMTP id r132so6527285oif.10 for ; Sat, 21 Jan 2023 03:36:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=O8Cz6k4KX1yuASkUSA4jvhy9POW2tYIOXU3qPPeNqdA=; b=H2uNCQfzVoFkMfmOhVo6YMOR1xGR9yHf2fXWCqqvhwr/Jhcwp1xoPpIDm/KBQs8a9A xQzfzPK8ex/AIaTWwNz4OpCK5WJ+9/e0c9wRsRoMStcRkYWlFdDmFmEsoG8SOyiUqD4T 7jt02wNfjz+nPnSJpOesqLPEGeaO6YeDY/I2PFk083+bBhzEtlDc3WdiM4xxuh34Kob9 jm04r4/aGHDs0OPrWynDE0LCqrawNXrbZFfpKm+AOFC0GtAdAIa8Ny4+17gkc3d+08pr qiJhCvJoa/dLs7McN7KpWh+wxePwjXaNEx41//cwgjZGWpj68wpY5hDarqiriqiKPuMM mB7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=O8Cz6k4KX1yuASkUSA4jvhy9POW2tYIOXU3qPPeNqdA=; b=SeltziAwWrPE2zHoGuHdkzmAtrM1ZLta5q8ZTWBRTVHLFkiS4wfSzwiLCpr2Izx8YK PSVIDICKFn4X1xH7OIdg6OycP4K8UOUi3f1Cf71gJ9KhxKHhPaGC33RF+8sUsRaqpS3V LiQI/QXPYUgwvcSI1U/oYcbvj4jnTbzGT6ihRp20gnvKlA8YeJ0RVZcQkiPo1B46RxRa PAVFUdRW9vg20NilmAqC0Hd5JFLqCIDm3civMWdL130URbCiZir369JaYyEvdOWkwSTW /vAm+ucbRG3K5XDdJdhg50ZJp2EuEnoFAKa/fAtlNsIY0DNPkbuhvsvScLtHU981vnDc bbuQ== X-Gm-Message-State: AFqh2kqguFFxlIPm8mj/qLT0c+RsgIYytFf6EvQGVyLiZ2N8qaHf4X+Z JtC3FFnGCckPAoLevdyKDnChxcKCEti3dBJfBQA= X-Google-Smtp-Source: AMrXdXt3rf5XK93ZUoEetuXSY2xqGM2NGG+Yz/id/iSoqmxbuBjdcFbQM33a3cnsdTLQrQxOlR8vY+qEc1SyoFh+LNY= X-Received: by 2002:a05:6808:15a:b0:35a:8ab0:70f0 with SMTP id h26-20020a056808015a00b0035a8ab070f0mr1063044oie.272.1674300985914; Sat, 21 Jan 2023 03:36:25 -0800 (PST) MIME-Version: 1.0 References: <20230114160201.en5g5bna66x6lnuw@awork3.anarazel.de> <20230117200432.xaoenn7ni7srb2l2@awork3.anarazel.de> In-Reply-To: From: Amit Kapila Date: Sat, 21 Jan 2023 17:06:14 +0530 Message-ID: Subject: Re: DROP DATABASE deadlocks with logical replication worker in PG 15.1 To: "houzj.fnst@fujitsu.com" Cc: Lakshmi Narayanan Sreethar , "pgsql-bugs@lists.postgresql.org" , Andres Freund Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Jan 19, 2023 at 4:37 PM Amit Kapila wrote: > > On Thu, Jan 19, 2023 at 3:46 PM houzj.fnst@fujitsu.com > wrote: > > > > On Thursday, January 19, 2023 3:14 PM houzj.fnst@fujitsu.com wrote: > > > On Wednesday, January 18, 2023 12:32 PM Amit Kapila > > > wrote: > > > > > > > > On Wed, Jan 18, 2023 at 1:34 AM Andres Freund wrote: > > > > > > > > > > On 2023-01-17 06:23:45 +0530, Amit Kapila wrote: > > > > > > > > > > > There is an analysis of the test > > > > > > failure in the email [2] which explains the race condition that > > > > > > leads to test failure. Thinking again about the failure, I feel we > > > > > > can instead change the failed test (t/004_sync.pl) to either > > > > > > ensure that both the walsenders (corresponding to sync worker and > > > > > > apply > > > > > > worker) exits after dropping the subscription and before checking > > > > > > the remaining slots on publisher or wait for slots to become zero > > > > > > in the test. > > > > > > > > > > How about waiting for the table to start to be synced (and thus the > > > > > slot to be > > > > > created) before issuing the drop subscription? > > > > > > > > > > > > > In this test [1], the initial sync fails due to a unique constraint > > > > violation, so checking that the sync has started is a bit tricky. We > > > > can probably check sync_error_count in pg_stat_subscription_stats to > > > > ensure that sync has started to fail which will ideally ensure that > > > > the sync has started. I am not sure this would be completely safe. The > > > > other possible ways are (a) after creating a subscription, wait for > > > > two slots to get created in the publisher, and then after dropping > > > > subscription wait for slots to become zero on the publisher; (b) after dropping > > > the subscription, wait for slots to become zero. > > > > > > > > I think one of (a) or (b) will work. > > > > > > I think in the mentioned testcase, the tablesync worker will keep restarting which > > > means the table sync slot is also being dropped and re-created ... . So, (a) waiting > > > for two slots to get created might not work as the slot will get dropped soon. I > > > think (b) waiting for slot to become zero would be a simpler way to make the test > > > stable. And here are the patches that tries to do it for all affected branches. > > > > When testing the patches on back-branches, I find that the reported deadlock > > problem doesn't happen on PG14 and rather start from PG15 after commit 4eb2176 > > which introduces the WaitForProcSignalBarrier logic in dropdb(). After this > > commit, when executing the bug-reproduction sql script, the DROP DATABASE will > > wait for the table sync worker to accept ProcSignalBarrier which can cause the > > reported deadlock problem. > > > > But I think it's still worth fixing this on PG14 as well, as it would be better > > to allow termination when executing command over network. > > > > I also think that this should be backpatched in PG14 as well. > I have verified it and it looks good to me. I'll push and backpatch this till PG14 on Tuesday unless there are more comments/suggestions. -- With Regards, Amit Kapila.