Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drrFR-0007PX-Us for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Sep 2017 19:53:30 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1drrFR-0003x8-Dp for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Sep 2017 19:53:29 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1drrDt-0000XH-Sk for pgsql-hackers@postgresql.org; Tue, 12 Sep 2017 19:51:54 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1drrDr-0001Rg-Be for pgsql-hackers@postgresql.org; Tue, 12 Sep 2017 19:51:52 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v8CJpkU7010938; Tue, 12 Sep 2017 15:51:46 -0400 From: Tom Lane To: Peter Eisentraut cc: Arseny Sher , pgsql-hackers@postgresql.org Subject: Re: DROP SUBSCRIPTION hangs if sub is disabled in the same transaction In-reply-to: <48b251c6-0652-c131-975a-835d8cdb003c@2ndquadrant.com> References: <87mv6av84w.fsf@ars-thinkpad> <48b251c6-0652-c131-975a-835d8cdb003c@2ndquadrant.com> Comments: In-reply-to Peter Eisentraut message dated "Tue, 12 Sep 2017 15:36:46 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <10936.1505245906.1@sss.pgh.pa.us> Date: Tue, 12 Sep 2017 15:51:46 -0400 Message-ID: <10937.1505245906@sss.pgh.pa.us> List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Peter Eisentraut writes: > I think we are whacking things around a in circle now. First we moved > the worker killing to the end of the transaction to make subscription > DDL transaction-capable. Then we changed replication origin dropping to > wait until the worker detaches. If you do both of these things at once, > you get this circular dependency. > We can break this in any number of ways: > - (your patch) Kill workers right away after ALTER SUBSCRIPTION DISABLE, > thus breaking the appearance of transactional DDL somewhat. > - Revert to the old behavior that the replication origin dropping fails > if it is in use. Then you would get an error instead of hanging. But > that was previously also reported as a bug. > - Disallow DROP SUBSCRIPTION in a transaction under certain > circumstances, for example if a transaction has previously manipulated > the same subscription. > - Have DROP SUBSCRIPTION attempt to kill workers if the subscription is > disabled (and possibly, was changed in the same transaction), which > would address this scenario very narrowly. ISTM the second of those (refuse to drop an in-use subscription) is by far the least surprising behavior. However, I wonder if there aren't race conditions involved here. What if we haven't yet committed a DROP SUBSCRIPTION, and some new worker starts up after we look for workers? If there aren't variants of that that will break all four options, it's not very obvious why not. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers