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 1k592K-0001w8-DN for pgsql-hackers@arkaria.postgresql.org; Mon, 10 Aug 2020 14:44:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k592J-00063R-3u for pgsql-hackers@arkaria.postgresql.org; Mon, 10 Aug 2020 14:44:27 +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 1k592I-00063J-Sm for pgsql-hackers@lists.postgresql.org; Mon, 10 Aug 2020 14:44:26 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k592G-000399-V1 for pgsql-hackers@lists.postgresql.org; Mon, 10 Aug 2020 14:44:25 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 07AEiLrE3195299; Mon, 10 Aug 2020 10:44:21 -0400 From: Tom Lane To: Robert Haas cc: Andres Freund , Bharath Rupireddy , PostgreSQL Hackers Subject: Re: Issue with cancel_before_shmem_exit while searching to remove a particular registered exit callbacks In-reply-to: References: <1519052.1594129481@sss.pgh.pa.us> <20200707165445.6qniqhzydlfsplvw@alap3.anarazel.de> <20200807212022.wocdoo2mmzhjsjm3@alap3.anarazel.de> Comments: In-reply-to Robert Haas message dated "Mon, 10 Aug 2020 10:29:54 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3195297.1597070661.1@sss.pgh.pa.us> Date: Mon, 10 Aug 2020 10:44:21 -0400 Message-ID: <3195298.1597070661@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Robert Haas writes: > Well, I don't really care whether or not we change this function to > iterate over the callback list or whether we add a warning that you > need to use it in LIFO order, but I think we should do one or the > other, because this same confusion has come up multiple times. I > thought that Tom was opposed to making it iterate over the callback > list (for reasons I don't really understand, honestly) so adding a > comment and a cross-check seemed like the practical option. Now I also > think it's fine to iterate over the callback list: this function > doesn't get used so much that it's likely to be a performance problem, > and I don't think this is the first bug that would have become a > non-bug had we done that years and years ago whenever it was first > proposed. In fact, I'd go so far as to say that the latter is a > slightly better option. However, doing nothing is clearly worst. I agree that doing nothing seems like a bad idea. My concern about allowing non-LIFO callback removal is that it seems to me that such usage patterns have likely got *other* bugs, so we should discourage that. These callbacks don't exist in a vacuum: they reflect that the mainline code path has set up, or torn down, important state. Non-LIFO usage requires very strong assumptions that the states in question are not interdependent, and that's something I'd rather not rely on if we don't have to. regards, tom lane