Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v24py-00056H-JI for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Sep 2025 09:33:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1v24oy-0002rn-5w for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Sep 2025 09:32:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v24ox-0002rf-Fg for pgsql-hackers@lists.postgresql.org; Fri, 26 Sep 2025 09:32:56 +0000 Received: from fhigh-a1-smtp.messagingengine.com ([103.168.172.152]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1v24ou-000Byy-1i for pgsql-hackers@postgresql.org; Fri, 26 Sep 2025 09:32:55 +0000 Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfhigh.phl.internal (Postfix) with ESMTP id 1388814000B9; Fri, 26 Sep 2025 05:32:50 -0400 (EDT) Received: from phl-imap-03 ([10.202.2.93]) by phl-compute-04.internal (MEProxy); Fri, 26 Sep 2025 05:32:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=compiler.org; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1758879170; x=1758965570; bh=QtWUwF/x+iSRPTWLWPvCcHpyuogqCyRcu0O1zyDAQgM=; b= FwBBDFsZ/GfrwZm8VkCtBGA3KfxVfiNupr+Z05bXjDGPcOQTMumf29LNI/gUOJsl ujjAYaWLLxtsp1Dzk5mMAURAZbLkEG5HxXZXJxappF4OyRaU+W6Ig3EdwnchhIUm TKmXfCKdedgDqlRbxHua3/Skb+vYV4a9xRyWyInONG8ae+t9kUqtKjON0bAR18WF wHRetAw3O99u+e7kXOPLAOjcwsCisFn9DMaX6CI6pl6gjKPI/+AfXCoiLQIBvbPN whZ5e/T09PzAJPun9bur+NPPo9ot7M0cUpYMfVQKm3NzrSMKjtlJfQCBWrjEcE7d mzT6xI3We/rHZFMq90Bjcw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1758879170; x= 1758965570; bh=QtWUwF/x+iSRPTWLWPvCcHpyuogqCyRcu0O1zyDAQgM=; b=P 2zaE/yJSPjVPFeHBODJ8ySTaBjfbGxiWKUJGiUZt3sIxc2GcNEcn0ocb4XLIjuP1 adAIUu51gXzFQqgHuHZIlK7NnX+P9S3lz3y+mfHDZi4NDYFpHCAPD4/WIDZ6oXx/ Ng0zWimf3pgAaDYyJOY8Vp6MOEzFQfCEU/Kn3q9o2AdblmAof4xWYamkEcipMWeQ u6Wfm+cjkCGApix59vdKMxvNmqwXZ75kVEjhJPTRoQK5rOWn0bFo5lmy9UI4onaC CCMkYjnKl3RBXtgI3Z6d7rvXaRB0pRKP3dvVb2HDyceKwwWJab/N7EphC/EXoI6+ ZUwoy9mGKw3HMvQXWP6qw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggdeiledtvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefoggffhffvvefkjghfufgtgfesthhqredtredtjeenucfhrhhomhepfdflohgvlhcu lfgrtghosghsohhnfdcuoehjohgvlhestghomhhpihhlvghrrdhorhhgqeenucggtffrrg htthgvrhhnpefggfeuheefheeufeegkeeifeffhffgvefftdduuefhfeelteegleehhfdt ieevgfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hjohgvlhestghomhhpihhlvghrrdhorhhgpdhnsggprhgtphhtthhopeeipdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehlihdrvghvrghnrdgthhgrohesghhmrghilhdrtg homhdprhgtphhtthhopehrihhshhhurdhpohhsthhgrhgvshesghhmrghilhdrtghomhdp rhgtphhtthhopehthhhomhgrshdrmhhunhhrohesghhmrghilhdrtghomhdprhgtphhtth hopehhlhhinhhnrghkrgesihhkihdrfhhipdhrtghpthhtohepphhgshhqlhdqhhgrtghk vghrshesphhoshhtghhrvghsqhhlrdhorhhgpdhrtghpthhtohepthhglhesshhsshdrph hghhdrphgrrdhush X-ME-Proxy: Feedback-ID: ic6394509:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 5052718E0069; Fri, 26 Sep 2025 05:32:49 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface MIME-Version: 1.0 X-ThreadId: AZ7XRsRLdGms Date: Fri, 26 Sep 2025 11:32:29 +0200 From: "Joel Jacobson" To: "Chao Li" Cc: "Tom Lane" , "Thomas Munro" , pgsql-hackers , "Heikki Linnakangas" , "Rishu Bagga" Message-Id: In-Reply-To: <52CC167F-763B-4ECA-B0B4-DAB381816828@gmail.com> References: <6899c044-4a82-49be-8117-e6f669765f7e@app.fastmail.com> <165530.1752362320@sss.pgh.pa.us> <02a7cd37-e2fc-4212-8b19-f8c239c95fb8@app.fastmail.com> <96f00bf1-cc9d-4520-9d02-9e14e7767c88@app.fastmail.com> <30c2aa7d-dd6c-4b68-a2e4-f217a1a34acf@app.fastmail.com> <0b4d402a-9ac2-4aa8-acf8-8231dbe579ea@app.fastmail.com> <3095599.1758644879@sss.pgh.pa.us> <0dc6a2cc-5216-4dc1-9dd2-430cafc6095b@app.fastmail.com> <52CC167F-763B-4ECA-B0B4-DAB381816828@gmail.com> Subject: Re: Optimize LISTEN/NOTIFY Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Sep 26, 2025, at 04:26, Chao Li wrote: > I think what you explained is partially correct. > > Based on my understanding, any backend process may call=20 > SignalBackends(), which means that it=E2=80=99s possible that multiple= backend=20 > processes may call SignalBackends() concurrently. > > Looking at your code, between checking=20 > QUEUE_BACKEND_WAKEUP_PENDING_FLAG(i) and set the flag to true, there i= s=20 > a block of code (the =E2=80=9Cif-else=E2=80=9D) to run, so that it=E2=80= =99s possible that=20 > multiple backend processes have passed the=20 > QUEUE_BACKEND_WAKEUP_PENDING_FLAG(i) check, then multiple signals will=20 > be sent to a process, which will lead to duplicate timeout enabled in=20 > the receiver process. I don't see how that can happen; we're checking wakeup_pending_flag while holding an exclusive lock, so I don't see how multiple backend processes could be within the region where we check/set wakeup_pending_flag, at the same time? /Joel