RE: [PG19] Promotion hangs behind a backend blocked on a stuck client

From: "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>
To: 'shihao zhong' <zhong950419(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Manu <manuelreyesbravo(at)gmail(dot)com>, Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, Noah Misch <noah(at)leadboat(dot)com>, 'Fujii Masao' <masao(dot)fujii(at)gmail(dot)com>
Subject: RE: [PG19] Promotion hangs behind a backend blocked on a stuck client
Date: 2026-10-15 13:06:00
Message-ID: OS7PR01MB18317B2378A08488597F36677F59C2@OS7PR01MB18317.jpnprd01.prod.outlook.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Shihao,

While discussing with LLM, I found that the current code might stuck in future,
when the callbacks in ProcessProcSignalBarrier() returns false.

According to the code comment, it can return false if it's not an appropriate
time thus we must try once again. At that time, the latch seems not to be set.
I came up with the below case for read:

1. callbacks in ProcessProcSignalBarrier() returns false.
2. it returns without seting the latch again.
3. secure_read() tries to read from the socket, but nothing found again
(errno == EAGAIN)
4. The backend reaches WaitEventSetWait() again. The caller side of the barrier
also keeps waiting.

I could reproduce with your patch set and below change. The reproducer could
stuck again on my env.

```
bool
ProcessBarrierSmgrRelease(void)
{
+ static bool defer_once = true;
+
+ /*
+ * If this called from ProcessClientBarrierInterrupt() for the first time,
+ * do no-op and returns false. This simulates the case we have to try once
+ * again.
+ */
+ if (ExitOnAnyError && defer_once)
+ {
+ defer_once = false;
+ return false;
+ }
+
```

Actually, I'm quite unclear how we should fix. Should we just note the risk
somewhere because it does not happen yet? Another primitive idea is to set the
latch again in ProcessClientBarrierInterrupt() if ProcSignalBarrierPending is still
true, but it may waste the CPU time, wait in the secure_read() may finish soon
and check the socket again may times.

Best regards,
Hayato Kuroda
FUJITSU LIMITED

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Aidar Imamov 2026-10-15 13:26:24 Re: Disable startup progress timeout during standby WAL replay
Previous Message David Rowley 2026-10-15 12:49:43 Re: Avoid repeated scans of the output buffer in oidvectortypes()