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 1v1yAm-00Eqn5-81 for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Sep 2025 02:27:00 +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 1v1yAk-007TPU-UC for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Sep 2025 02:26:58 +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 1v1yAk-007TPL-Jp for pgsql-hackers@lists.postgresql.org; Fri, 26 Sep 2025 02:26:58 +0000 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v1yAh-00088j-2U for pgsql-hackers@postgresql.org; Fri, 26 Sep 2025 02:26:58 +0000 Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-b57de3f63c8so314263a12.3 for ; Thu, 25 Sep 2025 19:26:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758853614; x=1759458414; darn=postgresql.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=3bOO4iscpAzjVyqXhpcMI5rKTXca+y4Z8rwG/ggXIqw=; b=Rb+0+h8fz8f5Ep/S/NhJgtEj7fQDDrDR4tOXOHM2drTM6Pu9weC5q/yzM/Kf557inc VW0/Zfw7eraFoB1BJQFlOdUMg0s1eyuuPugMivx3gu4MUwZjgmAko9jSOFNRSbvIvWUF d+VGPfIPTsQi2tDSXqnieu+b4cwnBTNY0BFUhHqSrMDtfBrj8doqmcSP/nSgFNvmYM12 mRVHnkPQUNqsYiTk1E3bekGFbHxkrBWu6VWCuRehz9IFp8z+lfKHBuUODjYHRBU+ZUFx 4JJz0O5uO9ctSTOZvv08ioYtcvoy6IKMOB2BfB1d3pJDn2omCYpWfIWZJO6eIR9yp86f QkKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758853614; x=1759458414; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3bOO4iscpAzjVyqXhpcMI5rKTXca+y4Z8rwG/ggXIqw=; b=Y2BHK+YxKVxuoqx7+c85jo1eo+/b+IYMWPXSOdooham61tpLRXC4UGMG0amENcbvTA Ekeyr8qC9UkbkDbn0ZdZ87+pJrHeCevVLn/I4ggedGlh2rIqHRR9QFa4cZQhhStosXTm b1AqDy5O/8/OEnHW2nv+50hwKH7V0Wh3uy8S7PCx5343PGpvsRc2qLrRibT/gQFV8Jxs sDwUjIFOXhpoVuQahe4SONPNBCTBOdqreDMbLPjKdQMUQdSwFYFL1ppjgm/z/xV/DgSL x3d88Hjvk9uXkyCYjm5m7agEwRZd5oJmQJF06ceHVdaHlnoE9pICxoQH/44nwS3dGqBo v0xQ== X-Forwarded-Encrypted: i=1; AJvYcCVE5akbYJCAAkk+/qgm00PNLGxfEQ2C3LsDzyEQ9pxiKAEgMSExKd+14VJj4s7Cz/AVON9Gf9bSUi1mT9kG@postgresql.org X-Gm-Message-State: AOJu0YyANkkTTREu9ldXgQlUNMjKESCJtFMzEpTm5ZtTJOiA8A6JQDA+ +7me71k3NOyXik8fJEC9JYOqLU9Co5LrFe3J2hZdM/z/M2pYH2nt/Uk7 X-Gm-Gg: ASbGncuzR9cmHkbCCplc8l/XyVMKZTTFw6W64BpPQdFkPoiCYUM9mKE8RlenHtSozK5 bbALrP+N8ZbKM4u8Ske033uesDxHQJ5RAQCdeOzcSdezrASEe7wIju0QF/Ev0xiU2wVRza+1sm2 tAelHwzU5Tz+FmrvcoN8Yy9ckFT186KRYnSv7X0d5DCNvr3rQK4zzz21+kzJm4UiN9A5VIJV8kC RaMc6t7+1VGk0vpXtHCrO+NpW0wCenzVPR/IcS0C+Lw36AilkMwB1FbDJZLN7OE0CVcfAqijnx9 +n2axLIjDCSUsb9o3OylyOUJTzmlYsjbl/e8XAvxF5EzjEMWleAoOv5lKb1P8McG8ACk7V61huT 8H4GxMdgS+Uc1xcT54UZpCYlIe1/TF+3j X-Google-Smtp-Source: AGHT+IGtugc7liTMFjBt7HzQbfbA+hXMfbCEsicI5+kZiBZVg4ScIosLpeLyKUpNNdJ8unwrNHGVuQ== X-Received: by 2002:a17:903:3d07:b0:276:305b:14a7 with SMTP id d9443c01a7336-27ed4a91a8cmr52469505ad.33.1758853613730; Thu, 25 Sep 2025 19:26:53 -0700 (PDT) Received: from smtpclient.apple ([142.171.105.12]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-27eec33b73dsm9658755ad.48.2025.09.25.19.26.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Sep 2025 19:26:53 -0700 (PDT) From: Chao Li Message-Id: <52CC167F-763B-4ECA-B0B4-DAB381816828@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_E28D944D-A489-4FD0-A1FB-B520A0546162" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: Optimize LISTEN/NOTIFY Date: Fri, 26 Sep 2025 10:26:37 +0800 In-Reply-To: Cc: Tom Lane , Thomas Munro , pgsql-hackers , Heikki Linnakangas , Rishu Bagga To: Joel Jacobson 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> X-Mailer: Apple Mail (2.3826.700.81) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_E28D944D-A489-4FD0-A1FB-B520A0546162 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Sep 26, 2025, at 05:13, Joel Jacobson wrote: >=20 > Hmm, I don't see how duplicate timeout could happen? >=20 > Once we decide to defer the wakeup, wakeup_pending_flag remains set, > which avoids further signals from notifiers, so I don't see how we = could > re-enter ProcessIncomingNotify(), since notifyInterruptPending is = reset > when ProcessIncomingNotify() is called, and notifyInterruptPending is > only set when a signal is received (or set directly when in same > process). >=20 I think what you explained is partially correct. Based on my understanding, any backend process may call = SignalBackends(), which means that it=E2=80=99s possible that multiple = backend processes may call SignalBackends() concurrently. Looking at your code, between checking = QUEUE_BACKEND_WAKEUP_PENDING_FLAG(i) and set the flag to true, there is = a block of code (the =E2=80=9Cif-else=E2=80=9D) to run, so that it=E2=80=99= s possible that multiple backend processes have passed the = QUEUE_BACKEND_WAKEUP_PENDING_FLAG(i) check, then multiple signals will = be sent to a process, which will lead to duplicate timeout enabled in = the receiver process. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/ --Apple-Mail=_E28D944D-A489-4FD0-A1FB-B520A0546162 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

On Sep 26, 2025, at 05:13, Joel Jacobson = <joel@compiler.org> wrote:

Hmm, I don't see how = duplicate timeout could happen?

Once we decide to defer the = wakeup, wakeup_pending_flag remains set,
which avoids further signals = from notifiers, so I don't see how we could
re-enter = ProcessIncomingNotify(), since notifyInterruptPending is reset
when = ProcessIncomingNotify() is called, and notifyInterruptPending is
only = set when a signal is received (or set directly when in = same
process).


I think what you explained is partially = correct.

Based on my understanding, any backend = process may call SignalBackends(), which means that it=E2=80=99s = possible that multiple backend processes may call SignalBackends() = concurrently.

Looking at your code, between = checking QUEUE_BACKEND_WAKEUP_PENDING_FLAG(i) and set the flag to true, = there is a block of code (the =E2=80=9Cif-else=E2=80=9D) to run, so that = it=E2=80=99s possible that multiple backend processes have passed the = QUEUE_BACKEND_WAKEUP_PENDING_FLAG(i) check, then multiple signals will = be sent to a process, which will lead to duplicate timeout enabled in = the receiver process.

Best regards,
--
Chao Li (Evan)
HighGo Software = Co., Ltd.
https://www.highgo.com/




= --Apple-Mail=_E28D944D-A489-4FD0-A1FB-B520A0546162--