Re: Exit walsender before confirming remote flush in logical replication

From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, Andrey Silitskiy <a(dot)silitskiy(at)postgrespro(dot)ru>, Alexander Korotkov <aekorotkov(at)gmail(dot)com>, Greg Sabino Mullane <htamfids(at)gmail(dot)com>, Japin Li <japinli(at)hotmail(dot)com>, Ronan Dunklau <ronan(at)dunklau(dot)fr>, Vitaly Davydov <v(dot)davydov(at)postgrespro(dot)ru>, "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>, "Takamichi Osumi (Fujitsu)" <osumi(dot)takamichi(at)fujitsu(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>, "sawada(dot)mshk(at)gmail(dot)com" <sawada(dot)mshk(at)gmail(dot)com>, "michael(at)paquier(dot)xyz" <michael(at)paquier(dot)xyz>, "peter(dot)eisentraut(at)enterprisedb(dot)com" <peter(dot)eisentraut(at)enterprisedb(dot)com>, "dilipbalaut(at)gmail(dot)com" <dilipbalaut(at)gmail(dot)com>, "amit(dot)kapila16(at)gmail(dot)com" <amit(dot)kapila16(at)gmail(dot)com>, Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>, Peter Smith <smithpb2250(at)gmail(dot)com>
Subject: Re: Exit walsender before confirming remote flush in logical replication
Date: 2026-04-24 10:29:08
Message-ID: CAHGQGwGW9w=KkHK-1t_30+27WB4Hgwy7cgQpjPM9BPdqTTD6+g@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Apr 24, 2026 at 11:05 AM Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
> ProcessPendingWrites() calls ProcessRepliesIfAny() in the first place, so if it is possible that, a new COPY message is appended after the already-queued CommandComplete? Which seems to violate the protocol, but I am not sure if that would lead to any trouble.
>
> So, maybe we need a new helper, say ProcessPendingWritesForShutdown(), that loops while pq_is_send_pending(), call WalSndCheckShutdownTimeout() and only wait for WL_SOCKET_WRITEABLE, then pq_flush_if_writable(), on flush failure, maybe WalSndShutdown().

Thanks for the review! You're right.

I added such loop directly in WalSndDone() instead of introducing a new helper
function, since only WalSndDone() needs it and the extra loop does not make
WalSndDone() significantly more complicated.

I've attached an updated patch.

Regards,

--
Fujii Masao

Attachment Content-Type Size
v2-0001-Avoid-blocking-indefinitely-while-finishing-walse.patch application/octet-stream 6.3 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jim Jones 2026-04-24 10:41:30 Re: PoC - psql - emphases line with table name in verbose output
Previous Message shveta malik 2026-04-24 10:24:35 Re: Proposal: Conflict log history table for Logical Replication