Re: FATAL: could not send end-of-streaming message to primary: no COPY in progress

From: Stepan Neretin <slpmcf(at)gmail(dot)com>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: FATAL: could not send end-of-streaming message to primary: no COPY in progress
Date: 2026-11-17 07:30:10
Message-ID: CA+Yyo5RsH3=Onfndt7+_HMAmxLMu_de9qq4f=JLvzEVeX0Xmdg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Nov 17, 2026 at 1:55 PM Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:

> On Tue, Nov 17, 2026 at 2:58 AM Stepan Neretin <slpmcf(at)gmail(dot)com> wrote:
> > The attached patch just remembers that CommandComplete already ended the
> > COPY, and skips PQputCopyEnd() in that case. No walsender change.
> >
> > Does this still seem worth fixing?
>
> Yes, I think.
>
> Thanks for the patch! I haven't read it yet, but when I ran CI with it,
> I observed that subscription/029_on_error failed with the following error:
>
> 436/436 postgresql:subscription / subscription/029_on_error
> ERROR 257.82s exit status 29
> ――――――――――――――――――――――――――――――――――――― ✀
> ―――――――――――――――――――――――――――――――――――――
> stderr:
> # poll_query_until timed out executing this query:
> # SELECT count(1) = 0 FROM pg_subscription_rel WHERE srsubstate NOT IN
> ('r', 's');
> # expecting this output:
> # t
> # last actual query output:
> # f
> # with stderr:
> # Last pg_subscription_rel contents:
> # 16392|16384|f|
> # die: timed out waiting for subscriber to synchronize data at
> /__w/postgresql/postgresql/src/test/subscription/t/029_on_error.pl
> line 130.
>
> (test program exited with status code 29)
>
> ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
>
> Regards,
>
> --
> Fujii Masao
>

Hi Fujii,

Thanks for checking. The 029_on_error failure was real.

receive() is also used for tablesync COPY TO STDOUT, so CommandComplete
there set copyEnded, and the later catchup stream reused that connection
and skipped CopyDone. v2 clears the flag in startstreaming().

029_on_error and 061_primary_shutdown_streaming both pass locally with
this.

Attached v2.

Regards,
Stepan Neretin

Attachment Content-Type Size
v2-0001-Fix-FATAL-when-primary-ends-streaming-with-COPY-0.patch text/x-patch 2.6 KB
v2-0002-Add-TAP-test-for-primary-shutdown-during-streaming.patch text/x-patch 1.8 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bertrand Drouvot 2026-11-17 07:38:25 Re: pgstat: Flush some statistics within running transactions, take 2
Previous Message Chao Li 2026-11-17 07:25:25 Re: [PATCH v1] pg_stash_advice: Reject embedded NUL bytes in persistence files