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

From: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
To: Stepan Neretin <slpmcf(at)gmail(dot)com>
Cc: 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-17 21:54:00
Message-ID: CAN4CZFM4+i5G1WThdW1EOU=prf3=C9SwSMv4w8S=uq3M_zsVww@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello

1.

> Subject: [PATCH v2 2/2] Add TAP test for primary shutdown during streaming

This should also have a meson.build edit so the meson builds also run
the new test

2. Stopping the primary and waiting a bit gives this on the standby:

LOG: replication terminated by primary server
DETAIL: End of WAL reached on timeline 1 at 0/030000B0.
FATAL: could not receive database system identifier and timeline ID
from the primary server: no connection to the server

After the early return walreceiver waits for new orders and then runs
IDENTIFY_SYSTEM on the closed connection. The test passes because it
only checks that the old message is gone.

3. On master, a clean publisher shutdown hits the same error in the
logical apply worker, and that disables a disable_on_error
subscription:

LOG: data stream from publisher has ended
ERROR: could not send end-of-streaming message to primary: server
closed the connection unexpectedly
LOG: subscription "sub" has been disabled because of an error

With the patch only the first line remains and the subscription stays
enabled. This doesn't seem like a bad thing, but probably should be
mentioned at least in the commit message, and maybe tested too?

4. Partial WAL segment archived on archive_mode=always standbys

Since endstreaming no longer fails, walreceiver continues into the
end-of-timeline block in WalReceiverMain(), which closes the current
segment and calls XLogArchiveNotify() on it, even though the segment
is incomplete.

Setup:

* standby with archive_mode = always and archive_command = 'test ! -f
arch/%f && cp %p arch/%f'
* stop the primary
* wait a few seconds
* start it again
* run pg_switch_wal() a few times:

master: archived while primary down: (none)
pg_stat_archiver: 5|000000010000000000000007|0|
patched: archived while primary down: 000000010000000000000003
pg_stat_archiver: 1|000000010000000000000003|6|000000010000000000000003

5. Would something like this work instead?

libpqrcv_endstreaming():
+ *next_tli = 0;
+ if (PQstatus(conn->streamConn) == CONNECTION_BAD)
+ return;
walreceiver.c, after walrcv_endstreaming(wrconn, &primaryTLI):
+ if (primaryTLI == 0)
+ proc_exit(0);

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Melanie Plageman 2026-11-17 21:54:08 Re: Fix ReadStream handling when heap rescan strategy changes
Previous Message Manu 2026-11-17 21:40:47 Re: Assertion failure with temporary relations in single-user mode