| From: | Stepan Neretin <slpmcf(at)gmail(dot)com> |
|---|---|
| To: | Xuneng Zhou <xunengzhou(at)gmail(dot)com> |
| Cc: | Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> |
| Subject: | Re: FATAL: could not send end-of-streaming message to primary: no COPY in progress |
| Date: | 2026-11-22 09:16:31 |
| Message-ID: | CA+Yyo5TqVUDqSyPs8fup50VOoULEksXZ0pRgsbLGOH892xZB4Q@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Sun, Nov 22, 2026 at 2:01 PM Xuneng Zhou <xunengzhou(at)gmail(dot)com> wrote:
> Hi Stepan,
>
> Thanks for updating v3.
>
> V3 skips the final CopyDone, but after COPY 0 both receivers leave the
> inner receive loop and can try to send feedback before reaching that
> check(WalReceiverMain -> XLogWalRcvSendReply, LogicalRepApplyLoop ->
> send_feedback). If feedback is due, the send can fail with no COPY in
> progress. We could add copyEnded to libpqrcv_send to guard it, though
> the callers could still mark the feedback as sent for skipping..
>
> For HEAD, I wonder if it would be clearer for walrcv_receive() to
> return two distinct values when the stream ends. With two return
> values, the function signature is intact and both callers would keep
> the existing handshake and send CopyDone after PGRES_COPY_IN. After
> PGRES_COMMAND_OK, the two could skip further sends and finish their
> local cleanup. This seems to change more and touch both loops, so I
> see it as an option for HEAD.
>
> Additionally,
>
> PQstatus(conn->streamConn) == CONNECTION_BAD
>
> Do we need this check in libpqrcv_endstreaming()?
> copyEnded already covers COPY 0. If it is false, the check could turn
> an unexpected disconnect into a clean exit. Is there a caller path
> that needs it?
>
>
> --
> Regards,
> Xuneng Zhou
> HighGo Software Co., Ltd.
>
Hi,
Thanks for the review. Agreed on both points.
After COPY 0, both receivers leave the inner loop and can still send
feedback before endstreaming. If a status update is due,
PQputCopyData() fails with no COPY in progress. v5 skips those sends
on the caller side once the stream has ended, instead of guarding
libpqrcv_send(), so we do not mark feedback as sent when nothing was
written. Local flush still happens via XLogWalRcvFlush(dying=true).
A second return value from walrcv_receive() for COMMAND_OK vs COPY_IN
looks clearer for HEAD. I would keep this fix smaller and
backpatchable, and leave that as a follow-up.
CONNECTION_BAD in endstreaming() is not needed. copyEnded already
covers COPY 0, and an abrupt disconnect normally ERROR's in receive()
before we get there. With next_tli == 0 doing proc_exit(0), that check
could also turn an unexpected disconnect into a quiet exit. Removed in
v5.
Attached.
Regards,
Stepan Neretin
| Attachment | Content-Type | Size |
|---|---|---|
| v5-0002-Add-TAP-tests-for-primary-publisher-shutdown-during-.patch | text/x-patch | 8.2 KB |
| v5-0001-Fix-FATAL-when-primary-ends-streaming-with-COPY-0.patch | text/x-patch | 6.2 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Pavlo Sukhanov | 2026-11-22 10:06:09 | Re: Python/pytest test framework take two |
| Previous Message | Chengpeng Yan | 2026-11-22 07:47:16 | Re: Simplify the uniqueness proof for self-join elimination |