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 1v251l-0006lK-HU for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Sep 2025 09:46:09 +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 1v250l-0008Lk-GG for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Sep 2025 09:45:08 +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 1v250l-0008Lc-5w for pgsql-hackers@lists.postgresql.org; Fri, 26 Sep 2025 09:45:07 +0000 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v250j-000C7T-0x for pgsql-hackers@postgresql.org; Fri, 26 Sep 2025 09:45:07 +0000 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-77f207d0891so1929612b3a.1 for ; Fri, 26 Sep 2025 02:45:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758879903; x=1759484703; 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=O8/MUho09VMORmtIO65TXtZrRQfFEmQbcB03mSTphyo=; b=MXyx9NCoJLKI5uLaJ+nmZvFMGm3ovgslMCWRaSCaGPxH/TUjEmBZzm8zomCDQC8X0j rUxzWGXorZb9BwIvWX8JJVl4KGHMgA+s8hCN6fVIyeAa0nE7ZGZB2l57butp1h0Aisj0 Qx+bAAaN3f4YYkHBwWH+ai5YERhiCrvAUpwZDMhLl991pXIDKi7EBjiZaYsWcAGQFMUZ m9En3GlWy7zmBXo6suP/7l3uoY3kH5SiluOmPFR7LD6GV/4H1qpYoOmEQr1mkSf8/6/n XKXecuKqIBxydIymGs03sU4UpcJJ/B1oeHXnV5UKXF0YZu4B0VoPIKe02e4MCFrq4bo1 ppUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758879903; x=1759484703; 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=O8/MUho09VMORmtIO65TXtZrRQfFEmQbcB03mSTphyo=; b=WkTy17Aj73iZ+0scT0b9/hgMc5/fhtbmj6czkYTQ3Z0TDa8lBTZ/+aLup5tav0GWOC fRrYtdsiQ5+nSzPuS0EY20SftlKbESr86JFTPlsJkosFNgCQ8CwrhmWvnte4+P4sC93y 7O7wMALTHkuFsltT8a7prqGVYud3CkWbvlRavLgGLf0mifxVn58MPa0RLM0pjA/LkQKz fV4nCeFamEz/skUHXLlkshgpgCN+gLL1VI3fGU/2HJCrjByDUBNyUy5YsFqX1SVp1Von 7nNb93wGjWYyaBVpqimaYRMKAW9TzNnN7FfobVNr/iTrp8hFvQfaH0Fn+xjVF9fDKVwx xdHA== X-Forwarded-Encrypted: i=1; AJvYcCWkBtZCnHOOKDyCkzQSJ2wtxVCvh9dvsXGabnt6G3tB+/EXYjAZE2Lkyd+8FztD8v789+8kgAuSFoI/NDDQ@postgresql.org X-Gm-Message-State: AOJu0Yxd/HDMk7Eu5ICA5ehz5Ju4ND0M3hU7JRnmdvkG2sNpQxpY/xcB l9s5LDOO6Bx+orlu55ICco4FQ9PM56jMv1NiMxdi8xjIzLdGexTkFAli X-Gm-Gg: ASbGncuZiePeXmof/XKcwfR1ejxKDhq3mVtGt3ZBOZbowePypwApC3oYRU8RY49JUcP mlImuFBJgIYdc2RtQhgeGBTjvSAetdDVFLxMUb7eIbH1g4if/YzJUZqOtdk9+YoF5Jr6q2uAVVz Bya0vkUutIXmfQT75a/zwYpUdhU7svJK5Qsl8a93d1CuENXB8ete26lEE7eZZLXVNEpEZ0wZKgW bW6ic9K7qpG1Ebc3Qqyqh3nqb+/UsO0e5kRtkxwcF2MQSBXw6N/Jbl4UgzcIvxeLIe0cj2PPbp2 0OQKJFv5RP2qyauY6aWt897RFWYFiMdYtT1YQNFfjuPCnPiUMFn9rwthd+C7NKrjlQVI+5wclYt 1ID2kSIB+ukWcMT9ASP/bewzWvuELufKl X-Google-Smtp-Source: AGHT+IH23zhXNGjOJEkJacw/CeNuTewOA1EwsQkL6E+mknkILdlJ3K6YHPTe3YckiCNLpexuMYtyag== X-Received: by 2002:a05:6a20:6a11:b0:2e5:655c:7f8e with SMTP id adf61e73a8af0-2e7bf478bebmr9198115637.6.1758879902637; Fri, 26 Sep 2025 02:45:02 -0700 (PDT) Received: from smtpclient.apple ([142.171.105.12]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-781023caa1fsm4046078b3a.33.2025.09.26.02.44.58 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Sep 2025 02:45:01 -0700 (PDT) From: Chao Li Message-Id: <9186C6D0-F7A9-482A-9183-89E530B57E36@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_DBE5BDA9-26C1-4523-A73D-3E4ABC47A2EE" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: Optimize LISTEN/NOTIFY Date: Fri, 26 Sep 2025 17:44:44 +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> <52CC167F-763B-4ECA-B0B4-DAB381816828@gmail.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=_DBE5BDA9-26C1-4523-A73D-3E4ABC47A2EE Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Sep 26, 2025, at 17:32, Joel Jacobson wrote: >=20 > On Fri, Sep 26, 2025, at 04:26, Chao Li wrote: >=20 >> I think what you explained is partially correct. >>=20 >> 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. >>=20 >> Looking at your code, between checking=20 >> QUEUE_BACKEND_WAKEUP_PENDING_FLAG(i) and set the flag to true, there = is=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. >=20 > 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? >=20 > /Joel I might miss the factor of holding an exclusive lock. I will revisit = that part again. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/ --Apple-Mail=_DBE5BDA9-26C1-4523-A73D-3E4ABC47A2EE Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

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

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
SignalBackends(), which means that it=E2=80=99= s 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.

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

I= might miss the factor of holding an exclusive lock. I will revisit that = part again.

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




= --Apple-Mail=_DBE5BDA9-26C1-4523-A73D-3E4ABC47A2EE--