pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
035_standby_logical_decoding might fail due to FATAL message lost inside libpq
12+ messages / 4 participants
[nested] [flat]

Commits from this thread:
  2026-10-22 d6cf162f74 9e3c7a062e 1b0888f69c 4ec789e1aa 5c0095e727  Fix slot names in the standby slot removal check
  2026-10-22 487b710bc4 9c0d6057c6 d7d45526e1 b8ab5237ee c1b3845ade  Fix a race in 035_standby_logical_decoding.pl
* 035_standby_logical_decoding might fail due to FATAL message lost inside libpq
@ 2026-05-17 15:00 Alexander Lakhin <exclusion@gmail.com>
  2026-05-27 05:43 ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Alexander Lakhin @ 2026-05-17 15:00 UTC (permalink / raw)
  To: pgsql-hackers

Hello hackers,

A recent buildfarm failure [1]:
  38/273 recovery - postgresql:recovery/035_standby_logical_decoding ERROR            74.36s   exit status 1

[14:34:25.522](0.001s) ok 65 - pg_recvlogical exited non-zero
[14:34:25.522](0.000s) not ok 66 - slot has been invalidated
[14:34:25.523](0.000s) #   Failed test 'slot has been invalidated'
#   at /home/bf/bf-build/francolin/REL_16_STABLE/pgsql/src/test/recovery/t/035_standby_logical_decoding.pl line 118.
[14:34:25.523](0.001s) #                   'pg_recvlogical: error: could not send replication command "START_REPLICATION 
SLOT "drop_db_activeslot" LOGICAL 0/0 ("include-xids" '0', "skip-empty-xacts" '1')": server closed the connection 
unexpectedly
#     This probably means the server terminated abnormally
#     before or while processing the request.
# pg_recvlogical: error: disconnected
# '
#     doesn't match '(?^:conflict with recovery)'
[14:34:25.675](0.152s) ok 67 - otherslot on standby not dropped

duplicated one that happened the last year [2] and had no explanation so
far. This time I've managed to reproduce it with the check_slots_dropped()
repeated in the loop (the patch is attached).

With extra logging added, I could see:
[08:47:52.385](0.000s) not ok 114 - slot has been invalidated
[08:47:52.385](0.000s) #   Failed test 'slot has been invalidated'
#   at /home/user/postgresql/src/test/recovery_9/t/035_standby_logical_decoding.pl line 120.
[08:47:52.385](0.000s) #                   '!!!pqsecure_raw_read| len=16384 n=554 errno=0 
buf=760000002b00030002000000015f70715f2e746573745f70726f746f636f6c5f6e65676f74696174696f6e00520000000800000000530000001b496e74657276616c5374796c6500706f7374677265730053000000207365617263685f7061746800222475736572222c207075626c696300530000001469735f737570657275736572006f6e0053000000237374616e646172645f636f6e666f726d696e675f737472696e6773006f6e00530000001f73657373696f6e5f617574686f72697a6174696f6e0075736572005300000019636c69656e745f656e636f64696e67005554463800530000001b7365727665725f76657273696f6e003139646576656c
# !!!pqsecure_raw_read| len=16384 n=85 errno=0 
buf=540000002300017365745f636f6e6669670000000000000000000019ffffffffffff0000440000000a000100000000430000000d53454c45435420310053000000117365617263685f7061746800005a0000000549
# !!!pqsecure_raw_read| len=16384 n=76 errno=0 
buf=540000002c0001646174615f6469726563746f72795f6d6f64650000000000000000000019ffffffffffff0000440000000e00010000000430373030430000000953484f57005a0000000549
# !!!pqsecure_raw_read| len=16384 n=198 errno=0 
buf=540000006f000473797374656d69640000000000000000000019ffffffffffff000074696d656c696e6500000000000000000000140008ffffffff0000786c6f67706f730000000000000000000019ffffffffffff000064626e616d650000000000000000000019ffffffffffff0000440000003a0004000000133736343038333834313938393731313334343000000001310000000a302f30373138433739380000000674657374646243000000144944454e544946595f53595354454d005a0000000549
# !!!pqsecure_raw_read| len=16384 n=181 errno=0 
buf=45000000b453464154414c0056464154414c00433537503034004d7465726d696e6174696e6720636f6e6e656374696f6e2064756520746f20636f6e666c6963742077697468207265636f766572790044557365722077617320636f6e6e656374656420746f20612064617461626173652074686174206d7573742062652064726f707065642e0046706f7374677265732e63004c3332313300527265706f72745f7265636f766572795f636f6e666c6963740000
### FATAL...57P04...terminating connection due to conflict with recovery
# !!!pqsecure_raw_read| len=16384 n=0 errno=0 buf=
# !!!pqsecure_raw_read| len=16384 n=0 errno=0 buf=
# pg_recvlogical: error: could not send replication command "START_REPLICATION SLOT "drop_db_activeslot" LOGICAL 
0/00000000 ("include-xids" '0', "skip-empty-xacts" '1')": server closed the connection unexpectedly
#       This probably means the server terminated abnormally
#       before or while processing the request.
# pg_recvlogical: error: disconnected
# '
#     doesn't match '(?^:conflict with recovery)'

That is, the FATAL message was received from the server, but libpq lost it inside.

A successful run shows this:
!!!check_pg_recvlogical_stderr:
!!!pqsecure_raw_read| len=16384 n=554 errno=0 
buf=760000002b00030002000000015f70715f2e746573745f70726f746f636f6c5f6e65676f74696174696f6e00520000000800000000530000001b496e74657276616c5374796c6500706f7374677265730053000000207365617263685f7061746800222475736572222c207075626c696300530000001469735f737570657275736572006f6e0053000000237374616e646172645f636f6e666f726d696e675f737472696e6773006f6e00530000001f73657373696f6e5f617574686f72697a6174696f6e0075736572005300000019636c69656e745f656e636f64696e67005554463800530000001b7365727665725f76657273696f6e003139646576656c
!!!pqsecure_raw_read| len=16384 n=85 errno=0 
buf=540000002300017365745f636f6e6669670000000000000000000019ffffffffffff0000440000000a000100000000430000000d53454c45435420310053000000117365617263685f7061746800005a0000000549
!!!pqsecure_raw_read| len=16384 n=76 errno=0 
buf=540000002c0001646174615f6469726563746f72795f6d6f64650000000000000000000019ffffffffffff0000440000000e00010000000430373030430000000953484f57005a0000000549
!!!pqsecure_raw_read| len=16384 n=198 errno=0 
buf=540000006f000473797374656d69640000000000000000000019ffffffffffff000074696d656c696e6500000000000000000000140008ffffffff0000786c6f67706f730000000000000000000019ffffffffffff000064626e616d650000000000000000000019ffffffffffff0000440000003a0004000000133736343038333834313938393731313334343000000001310000000a302f30364432393539380000000674657374646243000000144944454e544946595f53595354454d005a0000000549
!!!pqsecure_raw_read| len=16384 n=8 errno=0 buf=5700000007000000
!!!pqsecure_raw_read| len=16384 n=46 errno=0 
buf=64000000166b0000000006d295980002f5019f6590590064000000166b0000000006d295980002f5019f6590c100
!!!pqsecure_raw_read| len=16384 n=46 errno=0 
buf=64000000166b0000000006d295980002f5019f66df5b0064000000166b0000000006d295d00002f5019f66e01d00
!!!pqsecure_raw_read| len=16384 n=46 errno=0 
buf=64000000166b0000000006d295d00002f5019f6719390064000000166b0000000006d296a00002f5019f67197c00
!!!pqsecure_raw_read| len=16384 n=23 errno=0 buf=64000000166b0000000006d296a00002f5019f671b3300
!!!pqsecure_raw_read| len=16384 n=23 errno=0 buf=64000000166b0000000006d297800002f5019f671bc900
!!!pqsecure_raw_read| len=16384 n=46 errno=0 
buf=64000000166b0000000006d297800002f5019f671c970064000000166b0000000006d298000002f5019f671cbf00
!!!pqsecure_raw_read| len=16384 n=181 errno=0 
buf=45000000b453464154414c0056464154414c00433537503034004d7465726d696e6174696e6720636f6e6e656374696f6e2064756520746f20636f6e666c6963742077697468207265636f766572790044557365722077617320636f6e6e656374656420746f20612064617461626173652074686174206d7573742062652064726f707065642e0046706f7374677265732e63004c3332313300527265706f72745f7265636f766572795f636f6e666c6963740000
### FATAL...57P04...terminating connection due to conflict with recovery
pg_recvlogical: error: unexpected termination of replication stream: FATAL:  terminating connection due to conflict with 
recovery
DETAIL:  User was connected to a database that must be dropped.
pg_recvlogical: error: disconnected

Thus, FATAL is received by pg_recvlogical as expected, if it follows
CopyBothResponse in the stream.

Having this knowledge, I could reproduce such behavior simply with:
inline patch 1: src/backend/replication/walsender.c (+0/-0 lines) download inline-1.patch--- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -1501,6 +1501,7 @@ StartLogicalReplication(StartReplicationCmd *cmd)      ReplicationSlotAcquire(cmd->slotname, true, true);  +pg_usleep(1000000);      /*       * Force a disconnect, so that the decoding code doesn't need to care
      * about an eventual switch from running in recovery, to running in a # +++ tap check in src/test/recovery +++ t/035_standby_logical_decoding.pl .. 69/? #   Failed test 'slot has been invalidated' #   at t/035_standby_logical_decoding.pl line 119. #                   'pg_recvlogical: error: could not send replication command "START_REPLICATION SLOT "drop_db_activeslot" LOGICAL 0/00000000 ("include-xids" '0', "skip-empty-xacts" '1')": server closed the connection unexpectedly #       This probably means the server terminated abnormally #       before or while processing the request. # pg_recvlogical: error: disconnected # ' #     doesn't match '(?^:conflict with recovery)' t/035_standby_logical_decoding.pl .. 88/? # Looks like you failed 1 test of 89. Reproduced on REL_16_STABLE (where this test was landed) .. master. [1] https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=francolin&dt=2026-05-11%2012%3A25%3A04 [2] https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=kestrel&dt=2025-08-04%2005%3A45%3A46 Best regards, Alexander Patches and attachments: download all (2 files, .tar.gz)
debug-035_standby_logical_decoding.patch (text/x-patch, 3.6K) download diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c index a33a685dcc6..0c37ebdf9d1 100644 --- a/src/backend/replication/logical/logical.c +++ b/src/backend/replication/logical/logical.c @@ -603,6 +603,7 @@ CreateDecodingContext(XLogRecPtr start_lsn, ctx->reorder->output_rewrites = ctx->options.receive_rewrites; +pg_usleep(100000); ereport(LogicalDecodingLogLevel(), (errmsg("starting logical decoding for slot \"%s\"", NameStr(slot->data.name)), diff --git a/src/interfaces/libpq/fe-secure.c b/src/interfaces/libpq/fe-secure.c index 31d5b48d3f9..c08c2987c46 100644 --- a/src/interfaces/libpq/fe-secure.c +++ b/src/interfaces/libpq/fe-secure.c @@ -200,6 +200,16 @@ pqsecure_raw_read(PGconn *conn, void *ptr, size_t len) n = recv(conn->sock, ptr, len, 0); +if (conn->replication && conn->replication[0]) +{ +int save_errno = SOCK_ERRNO; +char hb[1024]; +hb[0] = 0; +for (size_t i = 0; i < n && i < 256; i++) sprintf(hb + (i * 2), "%02x", ((char *)ptr)[i]); +fprintf(stderr, "!!!pqsecure_raw_read| len=%zu n=%zd errno=%d buf=%s\n", len, n, (n < 0) ? save_errno : 0, hb); +SOCK_ERRNO_SET(save_errno); +} + if (n < 0) { result_errno = SOCK_ERRNO; diff --git a/src/test/meson.build b/src/test/meson.build index cd45cbf57fb..cbb6d70a439 100644 --- a/src/test/meson.build +++ b/src/test/meson.build @@ -5,6 +5,26 @@ subdir('isolation') subdir('authentication') subdir('postmaster') +subdir('recovery_1') +subdir('recovery_2') +subdir('recovery_3') +subdir('recovery_4') +subdir('recovery_5') +subdir('recovery_6') +subdir('recovery_7') +subdir('recovery_8') +subdir('recovery_9') +subdir('recovery_10') +subdir('recovery_11') +subdir('recovery_12') +subdir('recovery_13') +subdir('recovery_14') +subdir('recovery_15') +subdir('recovery_16') +subdir('recovery_17') +subdir('recovery_18') +subdir('recovery_19') +subdir('recovery_20') subdir('recovery') subdir('subscription') subdir('modules') diff --git a/src/test/recovery/t/035_standby_logical_decoding.pl b/src/test/recovery/t/035_standby_logical_decoding.pl index 4421059f100..44727a5d9f7 100644 --- a/src/test/recovery/t/035_standby_logical_decoding.pl +++ b/src/test/recovery/t/035_standby_logical_decoding.pl @@ -114,6 +114,7 @@ sub check_pg_recvlogical_stderr $slot_user_handle->finish; $return = $?; cmp_ok($return, "!=", 0, "pg_recvlogical exited non-zero"); +print("!!!check_pg_recvlogical_stderr:\n$stderr\n===\n"); if ($return) { like($stderr, qr/$check_stderr/, 'slot has been invalidated'); @@ -907,6 +908,10 @@ check_pg_recvlogical_stderr($handle, # drop the logical slots drop_logical_slots('wal_level_'); +for my $i (1 .. 100) +{ +print("DROP DATABASE scenario: iteration $i\n"); + # create the logical slots create_logical_slots($node_standby, 'drop_db_'); @@ -933,10 +938,17 @@ check_slots_dropped('drop_db', $handle); is($node_standby->slot('otherslot')->{'slot_type'}, 'logical', 'otherslot on standby not dropped'); +$node_standby->safe_psql('postgres', q[SELECT pg_drop_replication_slot('otherslot')]); +$node_primary->safe_psql('postgres', q[CREATE DATABASE testdb]); +$node_primary->wait_for_replay_catchup($node_standby); +} + # Cleanup : manually drop the slot that was not dropped. $node_standby->psql('postgres', q[SELECT pg_drop_replication_slot('otherslot')]); +if (0) +{ ################################################## # Test standby promotion and logical decoding behavior # after the standby gets promoted. @@ -1059,5 +1071,6 @@ chomp($cascading_stdout); is($cascading_stdout, $expected, 'got same expected output from pg_recvlogical decoding session on cascading standby' ); +} done_testing();
^ permalink raw reply [nested|flat] 12+ messages in thread

* RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq
  2026-05-17 15:00 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Alexander Lakhin <exclusion@gmail.com>
@ 2026-05-27 05:43 ` Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-05-27 17:00   ` Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Alexander Lakhin <exclusion@gmail.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Hayato Kuroda (Fujitsu) @ 2026-05-27 05:43 UTC (permalink / raw)
  To: Alexander Lakhin <exclusion@gmail.com>; +Cc: pgsql-hackers

Hi Alexander,

I applied your reproducer atop my HEAD (12d00048), but I could not reproduce.

In the first place, the postgres could not do the meson setup command after patching.
I got the below error:

```
Configuring Makefile.global using configuration

../postgres/src/test/meson.build:8:0: ERROR: Non-existent build file 'src/test/recovery_1/meson.build'
```

The build can be done if I restore changes in src/meson.build, but I could not
reproduce the failure if I run 035_standby_logicaldecoding.pl. Am I missing something?

Best regards,
Hayato Kuroda
FUJITSU LIMITED



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq
  2026-05-17 15:00 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Alexander Lakhin <exclusion@gmail.com>
  2026-05-27 05:43 ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
@ 2026-05-27 17:00   ` Alexander Lakhin <exclusion@gmail.com>
  2026-06-24 14:12     ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Alexander Lakhin @ 2026-05-27 17:00 UTC (permalink / raw)
  To: Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>; +Cc: pgsql-hackers

Hello Kuroda-san,

27.05.2026 08:43, Hayato Kuroda (Fujitsu) wrote:
> Hi Alexander,
>
> I applied your reproducer atop my HEAD (12d00048), but I could not reproduce.
> ...
>
> The build can be done if I restore changes in src/meson.build, but I could not
> reproduce the failure if I run 035_standby_logicaldecoding.pl. Am I missing something?

I'm sorry, it looks like I had messed up with the patch. Please try the fixed one.
It makes the unmodified 035_standby_logical_decoding.pl fail for me as below:
  CPPFLAGS="-O0" ./configure -q --enable-debug --enable-tap-tests --enable-injection-points && make -s -j8 && 
PROVE_TESTS="t/035*" make -s check -C src/test/recovery/
...
# pg_recvlogical: error: could not send replication command "START_REPLICATION SLOT "drop_db_activeslot" LOGICAL 
0/00000000 ("include-xids" '0', "skip-empty-xacts" '1')": server closed the connection unexpectedly
#       This probably means the server terminated abnormally
#       before or while processing the request.
# pg_recvlogical: error: disconnected
# '
#     doesn't match '(?^:conflict with recovery)'
t/035_standby_logical_decoding.pl .. 87/? # Looks like you failed 1 test of 89.
t/035_standby_logical_decoding.pl .. Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/89 subtests

Best regards,
Alexander

Attachments:

debug-035_standby_logical_decoding+.patch (text/x-patch, 1.7K) download diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c index b969caae72e..53eb0d711bc 100644 --- a/src/backend/replication/logical/logical.c +++ b/src/backend/replication/logical/logical.c @@ -600,6 +600,7 @@ CreateDecodingContext(XLogRecPtr start_lsn, ctx->reorder->output_rewrites = ctx->options.receive_rewrites; +pg_usleep(100000); ereport(LogicalDecodingLogLevel(), (errmsg("starting logical decoding for slot \"%s\"", NameStr(slot->data.name)), diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index 04aa770d981..687ac057afc 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -1501,6 +1501,7 @@ StartLogicalReplication(StartReplicationCmd *cmd) ReplicationSlotAcquire(cmd->slotname, true, true); +pg_usleep(500000); /* * Force a disconnect, so that the decoding code doesn't need to care * about an eventual switch from running in recovery, to running in a diff --git a/src/interfaces/libpq/fe-secure.c b/src/interfaces/libpq/fe-secure.c index 31d5b48d3f9..c08c2987c46 100644 --- a/src/interfaces/libpq/fe-secure.c +++ b/src/interfaces/libpq/fe-secure.c @@ -200,6 +200,16 @@ pqsecure_raw_read(PGconn *conn, void *ptr, size_t len) n = recv(conn->sock, ptr, len, 0); +if (conn->replication && conn->replication[0]) +{ +int save_errno = SOCK_ERRNO; +char hb[1024]; +hb[0] = 0; +for (size_t i = 0; i < n && i < 256; i++) sprintf(hb + (i * 2), "%02x", ((char *)ptr)[i]); +fprintf(stderr, "!!!pqsecure_raw_read| len=%zu n=%zd errno=%d buf=%s\n", len, n, (n < 0) ? save_errno : 0, hb); +SOCK_ERRNO_SET(save_errno); +} + if (n < 0) { result_errno = SOCK_ERRNO;
^ permalink raw reply [nested|flat] 12+ messages in thread

* RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq
  2026-05-17 15:00 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Alexander Lakhin <exclusion@gmail.com>
  2026-05-27 05:43 ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-05-27 17:00   ` Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Alexander Lakhin <exclusion@gmail.com>
@ 2026-06-24 14:12     ` Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-06-25 02:04       ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Hayato Kuroda (Fujitsu) @ 2026-06-24 14:12 UTC (permalink / raw)
  To: Alexander Lakhin <exclusion@gmail.com>; +Cc: pgsql-hackers

Dear Alexander,

Thanks for sharing and sorry for late reply. I was busy for the company work.
I analyzed the test failure and found a candidate reason.

Per my understanding, this can happen when the FATAL error is reported while
PQexec() is still running in StreamLogicalLog(). This behavior seems to come from
the current PQexecFinish() semantics for backward compatibility, so I do not
think we should fix the libpq code. Instead, the test should be adjusted.

The attached patch shows my analysis. It adds a sleep in StartLogicalReplication()
based on your reproducer, debug logs in PQexecFinish(), and debug output in the
test function check_pg_recvlogical_stderr(). Please apply the patch and run the
test once to follow the behavior described below.

[1] shows the result when the unexpected output happens with my debug logs.
Note that the test passed because the debug log itself contained terminating
connection due to conflict with recovery. However, the following line shows that
pg_recvlogical actually reported server closed the connection unexpectedly, which
is the wrong output.

The whole output in [1] indicates that two PGRES_FATAL_ERROR results were
consumed by PQexec() / PQexecFinish(), but only the second one was returned to
the pg_recvlogical layer. This is the root cause. However, this seems to be
intentional behavior: the comment in PQexecFinish() says that only the last
result is returned for backward compatibility.

pg_usleep() is needed for the reproducer because the issue can happen only when
the FATAL error is reported during the PQexec() call for `START_REPLICATION ...`.
[2] shows the case without the sleep. In that case, the error was reported after
PQexec() had already returned PGRES_COPY_BOTH. Then PQgetCopyData(conn, &copybuf, 1)
detected the FATAL error, and the subsequent code reported it as an unexpected
termination of the replication stream.

To address this issue, I think the test should ensure that pg_recvlogical has
finished running PQexec() and entered the COPY BOTH receive loop. Let me
investigate that a bit more.

How do you feel the analysis?

[1]: 
```
[22:21:11.808](0.000s) ok 78 - slot has been invalidated
PQexecFinish loop: errMsg=(null)
PQexecFinish return: errMsg=(null)
PQexecFinish loop: errMsg=(null)
PQexecFinish return: errMsg=(null)
PQexecFinish loop: errMsg=(null)
PQexecFinish return: errMsg=(null)
PQexecFinish loop: errMsg=FATAL:  terminating connection due to conflict with recovery
DETAIL:  User was connected to a database that must be dropped.

PQexecFinish loop: errMsg=server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.

PQexecFinish return: errMsg=server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.

pg_recvlogical: debug: after PQexec
pg_recvlogical: error: could not send replication command "START_REPLICATION SLOT "drop_db_activeslot" LOGICAL 0/00000000 ("include-xids" '0', "skip-empty-xacts" '1')": server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.
```

[2]:
```
[22:43:45.508](0.000s) ok 78 - slot has been invalidated
PQexecFinish loop: errMsg=(null)
PQexecFinish return: errMsg=(null)
PQexecFinish loop: errMsg=(null)
PQexecFinish return: errMsg=(null)
PQexecFinish loop: errMsg=(null)
PQexecFinish return: errMsg=(null)
PQexecFinish loop: errMsg=(null)
PQexecFinish return: errMsg=(null)
pg_recvlogical: debug: after PQexec
pg_recvlogical: error: unexpected termination of replication stream: FATAL:  terminating connection due to conflict with recovery
DETAIL:  User was connected to a database that must be dropped.
```

Best regards,
Hayato Kuroda
FUJITSU LIMITED



Attachments:

0001-Analyze-035_standby_logical_decoding-failure.patch (application/octet-stream, 2.6K) download From dc782b923428db6c24cf4f53251f7a810fa0a27c Mon Sep 17 00:00:00 2001 From: Hayato Kuroda <kuroda.hayato@fujitsu.com> Date: Wed, 24 Jun 2026 22:16:14 +0900 Subject: [PATCH] Analyze 035_standby_logical_decoding failure --- src/backend/replication/walsender.c | 1 + src/bin/pg_basebackup/pg_recvlogical.c | 1 + src/interfaces/libpq/fe-exec.c | 7 +++++++ src/test/recovery/t/035_standby_logical_decoding.pl | 1 + 4 files changed, 10 insertions(+) diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index c931d9b4fa8..3ca2327dc56 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -1523,6 +1523,7 @@ StartLogicalReplication(StartReplicationCmd *cmd) ReplicationSlotAcquire(cmd->slotname, true, true); +pg_usleep(500000); /* * Force a disconnect, so that the decoding code doesn't need to care * about an eventual switch from running in recovery, to running in a diff --git a/src/bin/pg_basebackup/pg_recvlogical.c b/src/bin/pg_basebackup/pg_recvlogical.c index 0f7d7fe9429..24b65dc75e5 100644 --- a/src/bin/pg_basebackup/pg_recvlogical.c +++ b/src/bin/pg_basebackup/pg_recvlogical.c @@ -277,6 +277,7 @@ StreamLogicalLog(void) appendPQExpBufferChar(query, ')'); res = PQexec(conn, query->data); + pg_log_info("debug: after PQexec"); if (PQresultStatus(res) != PGRES_COPY_BOTH) { pg_log_error("could not send replication command \"%s\": %s", diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c index 7b8edacbfde..97da4b3a472 100644 --- a/src/interfaces/libpq/fe-exec.c +++ b/src/interfaces/libpq/fe-exec.c @@ -2443,6 +2443,9 @@ PQexecFinish(PGconn *conn) lastResult = NULL; while ((result = PQgetResult(conn)) != NULL) { + fprintf(stderr, + "PQexecFinish loop: errMsg=%s\n", + result->errMsg ? result->errMsg : "(null)"); PQclear(lastResult); lastResult = result; if (result->resultStatus == PGRES_COPY_IN || @@ -2452,6 +2455,10 @@ PQexecFinish(PGconn *conn) break; } + fprintf(stderr, + "PQexecFinish return: errMsg=%s\n", + lastResult->errMsg ? lastResult->errMsg : "(null)"); + return lastResult; } diff --git a/src/test/recovery/t/035_standby_logical_decoding.pl b/src/test/recovery/t/035_standby_logical_decoding.pl index 88893f71350..a6abfbf8464 100644 --- a/src/test/recovery/t/035_standby_logical_decoding.pl +++ b/src/test/recovery/t/035_standby_logical_decoding.pl @@ -119,6 +119,7 @@ sub check_pg_recvlogical_stderr like($stderr, qr/$check_stderr/, 'slot has been invalidated'); } + print $stderr. "\n"; return 0; } -- 2.52.0
^ permalink raw reply [nested|flat] 12+ messages in thread

* RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq
  2026-05-17 15:00 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Alexander Lakhin <exclusion@gmail.com>
  2026-05-27 05:43 ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-05-27 17:00   ` Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Alexander Lakhin <exclusion@gmail.com>
  2026-06-24 14:12     ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
@ 2026-06-25 02:04       ` Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-06-28 12:00         ` Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Alexander Lakhin <exclusion@gmail.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Hayato Kuroda (Fujitsu) @ 2026-06-25 02:04 UTC (permalink / raw)
  To: Alexander Lakhin <exclusion@gmail.com>; +Cc: pgsql-hackers; Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>

Hi Alexander,

While sleeping, I came up with the idea; instead of waiting until the slot is
active, we can wait pg_recvlogical receives the ack from the walsender and enters
the loop. Attached patch implemented like that.

On my env, the patch could resolve the issue. How do you feel?

Best regards,
Hayato Kuroda
FUJITSU LIMITED



Attachments:

0001-Fix-test-failure-035_standby_logical_decoding.patch (application/octet-stream, 2.0K) download From 522c33b8636e18fc5c192e35b6ff746a8a55c899 Mon Sep 17 00:00:00 2001 From: Hayato Kuroda <kuroda.hayato@fujitsu.com> Date: Thu, 25 Jun 2026 11:00:23 +0900 Subject: [PATCH] Fix test failure 035_standby_logical_decoding --- .../recovery/t/035_standby_logical_decoding.pl | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/test/recovery/t/035_standby_logical_decoding.pl b/src/test/recovery/t/035_standby_logical_decoding.pl index 88893f71350..6074577f98e 100644 --- a/src/test/recovery/t/035_standby_logical_decoding.pl +++ b/src/test/recovery/t/035_standby_logical_decoding.pl @@ -71,8 +71,9 @@ sub drop_logical_slots } # Acquire one of the standby logical slots created by create_logical_slots(). -# In case wait is true we are waiting for an active pid on the 'activeslot' slot. -# If wait is not true it means we are testing a known failure scenario. +# If wait is true, wait until pg_recvlogical has completed START_REPLICATION +# and entered streaming mode. If wait is not true, it means we are testing a +# known failure scenario. sub make_slot_active { my ($node, $slot_prefix, $wait, $to_stdout, $to_stderr) = @_; @@ -87,6 +88,7 @@ sub make_slot_active '--option' => 'include-xids=0', '--option' => 'skip-empty-xacts=1', '--file' => '-', + '--verbose', '--no-loop', '--start', ], @@ -96,10 +98,14 @@ sub make_slot_active if ($wait) { - # make sure activeslot is in use - $node->poll_query_until('testdb', - qq[SELECT EXISTS (SELECT 1 FROM pg_replication_slots WHERE slot_name = '$active_slot' AND active_pid IS NOT NULL)] - ) or die "slot never became active"; + my $pump_timeout = + IPC::Run::timer($PostgreSQL::Test::Utils::timeout_default); + + # Make sure that pg_recvlogical has finished START_REPLICATION + # and entered the COPY BOTH receive loop. + ok(pump_until($slot_user_handle, $pump_timeout, $to_stderr, + qr/streaming initiated/), + "pg_recvlogical started streaming"); } return $slot_user_handle; } -- 2.52.0
^ permalink raw reply [nested|flat] 12+ messages in thread

* Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq
  2026-05-17 15:00 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Alexander Lakhin <exclusion@gmail.com>
  2026-05-27 05:43 ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-05-27 17:00   ` Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Alexander Lakhin <exclusion@gmail.com>
  2026-06-24 14:12     ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-06-25 02:04       ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
@ 2026-06-28 12:00         ` Alexander Lakhin <exclusion@gmail.com>
  2026-09-02 01:47           ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Alexander Lakhin @ 2026-06-28 12:00 UTC (permalink / raw)
  To: Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>; +Cc: pgsql-hackers

Hello Kuroda-san,

25.06.2026 05:04, Hayato Kuroda (Fujitsu) wrote:
> While sleeping, I came up with the idea; instead of waiting until the slot is
> active, we can wait pg_recvlogical receives the ack from the walsender and enters
> the loop. Attached patch implemented like that.
>
> On my env, the patch could resolve the issue. How do you feel?

Thank you for the fix!

I agree with your idea -- It makes sense to me to modify make_slot_active()
so that it returns the handle of pg_recvlogical after it reaches the
desired state from its own perspective.

With the the above repro modification applied, the fixed test passes for
me too.

Best regards,
Alexander





^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq
  2026-05-17 15:00 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Alexander Lakhin <exclusion@gmail.com>
  2026-05-27 05:43 ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-05-27 17:00   ` Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Alexander Lakhin <exclusion@gmail.com>
  2026-06-24 14:12     ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-06-25 02:04       ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-06-28 12:00         ` Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Alexander Lakhin <exclusion@gmail.com>
@ 2026-09-02 01:47           ` Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-09-02 05:15             ` Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Hayato Kuroda (Fujitsu) @ 2026-09-02 01:47 UTC (permalink / raw)
  To: pgsql-hackers; +Cc: Alexander Lakhin <exclusion@gmail.com>

Hi hackers,

Ping - I registered this thread in CF [1] not to forget.
This tries to fix a flaky test.

[1]: https://commitfest.postgresql.org/patch/7247/

Best regards,
Hayato Kuroda
FUJITSU LIMITED



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq
  2026-05-17 15:00 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Alexander Lakhin <exclusion@gmail.com>
  2026-05-27 05:43 ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-05-27 17:00   ` Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Alexander Lakhin <exclusion@gmail.com>
  2026-06-24 14:12     ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-06-25 02:04       ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-06-28 12:00         ` Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Alexander Lakhin <exclusion@gmail.com>
  2026-09-02 01:47           ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
@ 2026-09-02 05:15             ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
  2026-09-02 05:42               ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Bertrand Drouvot @ 2026-09-02 05:15 UTC (permalink / raw)
  To: Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>; +Cc: pgsql-hackers; Alexander Lakhin <exclusion@gmail.com>

Hi,

On Wed, Sep 02, 2026 at 01:47:00AM +0000, Hayato Kuroda (Fujitsu) wrote:
> Hi hackers,
> 
> Ping

Thanks! ;-)

> This tries to fix a flaky test.

                        '--option' => 'skip-empty-xacts=1',
                        '--file' => '-',
+                       '--verbose',

Adding verbose does not add too much noise to the output so that's ok for me.

It is also needed for:

+               ok(pump_until($slot_user_handle, $pump_timeout, $to_stderr,
+                                         qr/streaming initiated/),
+                  "pg_recvlogical started streaming");

Waiting for "streaming initiated" makes sense to me.

The patch LGTM.

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com





^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq
  2026-05-17 15:00 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Alexander Lakhin <exclusion@gmail.com>
  2026-05-27 05:43 ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-05-27 17:00   ` Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Alexander Lakhin <exclusion@gmail.com>
  2026-06-24 14:12     ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-06-25 02:04       ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-06-28 12:00         ` Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Alexander Lakhin <exclusion@gmail.com>
  2026-09-02 01:47           ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-09-02 05:15             ` Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
@ 2026-09-02 05:42               ` Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-10-20 15:08                 ` Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Fujii Masao <masao.fujii@gmail.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Hayato Kuroda (Fujitsu) @ 2026-09-02 05:42 UTC (permalink / raw)
  To: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; +Cc: pgsql-hackers; Alexander Lakhin <exclusion@gmail.com>

Dear Bertrand,

> The patch LGTM.

That's great. I changed the status to "Ready for Committer".

Best regards,
Hayato Kuroda
FUJITSU LIMITED







^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq
  2026-05-17 15:00 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Alexander Lakhin <exclusion@gmail.com>
  2026-05-27 05:43 ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-05-27 17:00   ` Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Alexander Lakhin <exclusion@gmail.com>
  2026-06-24 14:12     ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-06-25 02:04       ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-06-28 12:00         ` Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Alexander Lakhin <exclusion@gmail.com>
  2026-09-02 01:47           ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-09-02 05:15             ` Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
  2026-09-02 05:42               ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
@ 2026-10-20 15:08                 ` Fujii Masao <masao.fujii@gmail.com>
  2026-10-21 06:37                   ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Fujii Masao @ 2026-10-20 15:08 UTC (permalink / raw)
  To: Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>; +Cc: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; pgsql-hackers; Alexander Lakhin <exclusion@gmail.com>

On Wed, Sep 2, 2026 at 2:42 PM Hayato Kuroda (Fujitsu)
<kuroda.hayato@fujitsu.com> wrote:
> That's great. I changed the status to "Ready for Committer".

I've started reviewing this patch since it's marked as ready for committer.
I have two review comments.

+ my $pump_timeout =
+   IPC::Run::timer($PostgreSQL::Test::Utils::timeout_default);

This timer is never started or passed to IPC::Run::start(), so it seems
it can never expire. Right? If so, isn't it better to reuse the existing
timeout for pump_until()?

+ ok(pump_until($slot_user_handle, $pump_timeout, $to_stderr,
+   qr/streaming initiated/),
+    "pg_recvlogical started streaming");

This allows the test to continue even if pump_until() returns false.
Since streaming is a prerequisite for the subsequent steps, we should
use or die(), as the old code did?

Attached 0001 addresses these comments.

I also found a pre-existing typo: the slots are created with the prefix
"drop_db_", but their removal is checked using "drop_db". Since
those names never existed, the checks pass even if the actual slots
remain. Attached 0002 fixes this.

Regards,


-- 
Fujii Masao

Attachments: download all (3 files, .tar.gz)

v2-0002-Fix-slot-names-in-the-standby-slot-removal-check.patch (application/octet-stream, 1.3K) download From 28666bfb41981b2e085af7e3bfa333aea08c2880 Mon Sep 17 00:00:00 2001 From: Fujii Masao <fujii@postgresql.org> Date: Tue, 20 Oct 2026 22:24:42 +0900 Subject: [PATCH v2 2/2] Fix slot names in the standby slot removal check The DROP DATABASE test in 035_standby_logical_decoding.pl created slots with the prefix "drop_db_" but checked for their removal using "drop_db". Sined names never existed, the checks passed even if the actual slots remained. Fix this by using the correct prefix when checking for slot removal. Backpatch to v16, where this testce the check was introduced. Backpatch-through: 16 --- src/test/recovery/t/035_standby_logical_decoding.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/recovery/t/035_standby_logical_decoding.pl b/src/test/recovery/t/035_standby_logical_decoding.pl index a9b1968a6e2..c5f73041566 100644 --- a/src/test/recovery/t/035_standby_logical_decoding.pl +++ b/src/test/recovery/t/035_standby_logical_decoding.pl @@ -930,7 +930,7 @@ is( $node_standby->safe_psql( 'f', 'database dropped on standby'); -check_slots_dropped('drop_db', $handle); +check_slots_dropped('drop_db_', $handle); is($node_standby->slot('otherslot')->{'slot_type'}, 'logical', 'otherslot on standby not dropped'); -- 2.56.0
v2-0001-Fix-a-race-in-035_standby_logical_decoding.pl.patch (application/octet-stream, 3.4K) download From 92153d80490b25345dca780bbdff8290f83ca9c8 Mon Sep 17 00:00:00 2001 From: Hayato Kuroda <kuroda.hayato@fujitsu.com> Date: Thu, 25 Jun 2026 11:00:23 +0900 Subject: [PATCH v2] Fix a race in 035_standby_logical_decoding.pl Buildfarm animals francolin and kestrel reported intermittent failures in 035_standby_logical_decoding.pl. The test checks that replaying DROP DATABASE on a standby terminates pg_recvlogical with the expected recovery-conflict message and removes the database's replication slots. To exercise this while pg_recvlogical is streaming, the test must wait for streaming to start before dropping the database on the primary. Previously, the test treated an active slot in pg_replication_slots as confirmation that pg_recvlogical was streaming. However, the slot can become active before pg_recvlogical has entered streaming mode. If DROP DATABASE is replayed during this window, pg_recvlogical can report a connection-closed error instead of the recovery-conflict message, causing the test to fail. Run pg_recvlogical with --verbose and wait for "streaming initiated" instead of checking whether the slot is active. This ensures that pg_recvlogical has entered streaming mode before the database is dropped on the primary. Back-patch to v16, where this test was introduced. Reported-by: Alexander Lakhin <exclusion@gmail.com> Author: Hayato Kuroda <kuroda.hayato@fujitsu.com> Reviewed-by: Alexander Lakhin <exclusion@gmail.com> Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com> Discussion: https://postgr.es/m/a50ff89b-fb2c-4912-8f89-50dd0bd0916b@gmail.com Backpatch-through: 16 --- .../recovery/t/035_standby_logical_decoding.pl | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/test/recovery/t/035_standby_logical_decoding.pl b/src/test/recovery/t/035_standby_logical_decoding.pl index 88893f71350..a9b1968a6e2 100644 --- a/src/test/recovery/t/035_standby_logical_decoding.pl +++ b/src/test/recovery/t/035_standby_logical_decoding.pl @@ -71,12 +71,13 @@ sub drop_logical_slots } # Acquire one of the standby logical slots created by create_logical_slots(). -# In case wait is true we are waiting for an active pid on the 'activeslot' slot. -# If wait is not true it means we are testing a known failure scenario. +# If wait is true, wait for pg_recvlogical to enter streaming mode. +# Otherwise, starting replication is expected to fail. sub make_slot_active { my ($node, $slot_prefix, $wait, $to_stdout, $to_stderr) = @_; my $slot_user_handle; + my $timeout = IPC::Run::timeout($default_timeout); my $active_slot = $slot_prefix . 'activeslot'; $slot_user_handle = IPC::Run::start( @@ -87,19 +88,20 @@ sub make_slot_active '--option' => 'include-xids=0', '--option' => 'skip-empty-xacts=1', '--file' => '-', + '--verbose', '--no-loop', '--start', ], '>' => $to_stdout, '2>' => $to_stderr, - IPC::Run::timeout($default_timeout)); + $timeout); if ($wait) { - # make sure activeslot is in use - $node->poll_query_until('testdb', - qq[SELECT EXISTS (SELECT 1 FROM pg_replication_slots WHERE slot_name = '$active_slot' AND active_pid IS NOT NULL)] - ) or die "slot never became active"; + # Make sure that pg_recvlogical has entered streaming mode. + pump_until($slot_user_handle, $timeout, $to_stderr, + qr/streaming initiated/) + or die "pg_recvlogical did not enter streaming mode"; } return $slot_user_handle; } -- 2.56.0
nocfbot-v2-0001-PG16_PG17-Fix-a-race-in-035_standby_logical_decoding.pl.patch (application/octet-stream, 3.4K) download From 740539c90d489ceef7ae47ac10272122e22da889 Mon Sep 17 00:00:00 2001 From: Hayato Kuroda <kuroda.hayato@fujitsu.com> Date: Thu, 25 Jun 2026 11:00:23 +0900 Subject: [PATCH v2] Fix a race in 035_standby_logical_decoding.pl Buildfarm animals francolin and kestrel reported intermittent failures in 035_standby_logical_decoding.pl. The test checks that replaying DROP DATABASE on a standby terminates pg_recvlogical with the expected recovery-conflict message and removes the database's replication slots. To exercise this while pg_recvlogical is streaming, the test must wait for streaming to start before dropping the database on the primary. Previously, the test treated an active slot in pg_replication_slots as confirmation that pg_recvlogical was streaming. However, the slot can become active before pg_recvlogical has entered streaming mode. If DROP DATABASE is replayed during this window, pg_recvlogical can report a connection-closed error instead of the recovery-conflict message, causing the test to fail. Run pg_recvlogical with --verbose and wait for "streaming initiated" instead of checking whether the slot is active. This ensures that pg_recvlogical has entered streaming mode before the database is dropped on the primary. Back-patch to v16, where this test was introduced. Reported-by: Alexander Lakhin <exclusion@gmail.com> Author: Hayato Kuroda <kuroda.hayato@fujitsu.com> Reviewed-by: Alexander Lakhin <exclusion@gmail.com> Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com> Discussion: https://postgr.es/m/a50ff89b-fb2c-4912-8f89-50dd0bd0916b@gmail.com Backpatch-through: 16 --- .../recovery/t/035_standby_logical_decoding.pl | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/test/recovery/t/035_standby_logical_decoding.pl b/src/test/recovery/t/035_standby_logical_decoding.pl index 9c5b1ba64a8..c9a75d231dc 100644 --- a/src/test/recovery/t/035_standby_logical_decoding.pl +++ b/src/test/recovery/t/035_standby_logical_decoding.pl @@ -69,12 +69,13 @@ sub drop_logical_slots } # Acquire one of the standby logical slots created by create_logical_slots(). -# In case wait is true we are waiting for an active pid on the 'activeslot' slot. -# If wait is not true it means we are testing a known failure scenario. +# If wait is true, wait for pg_recvlogical to enter streaming mode. +# Otherwise, starting replication is expected to fail. sub make_slot_active { my ($node, $slot_prefix, $wait, $to_stdout, $to_stderr) = @_; my $slot_user_handle; + my $timeout = IPC::Run::timeout($default_timeout); my $active_slot = $slot_prefix . 'activeslot'; $slot_user_handle = IPC::Run::start( @@ -85,20 +86,20 @@ sub make_slot_active 'include-xids=0', '-o', 'skip-empty-xacts=1', '--no-loop', '--start', '-f', - '-' + '-', '--verbose' ], '>', $to_stdout, '2>', $to_stderr, - IPC::Run::timeout($default_timeout)); + $timeout); if ($wait) { - # make sure activeslot is in use - $node->poll_query_until('testdb', - qq[SELECT EXISTS (SELECT 1 FROM pg_replication_slots WHERE slot_name = '$active_slot' AND active_pid IS NOT NULL)] - ) or die "slot never became active"; + # Make sure that pg_recvlogical has entered streaming mode. + pump_until($slot_user_handle, $timeout, $to_stderr, + qr/streaming initiated/) + or die "pg_recvlogical did not enter streaming mode"; } return $slot_user_handle; } -- 2.56.0
^ permalink raw reply [nested|flat] 12+ messages in thread

* RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq
  2026-05-17 15:00 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Alexander Lakhin <exclusion@gmail.com>
  2026-05-27 05:43 ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-05-27 17:00   ` Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Alexander Lakhin <exclusion@gmail.com>
  2026-06-24 14:12     ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-06-25 02:04       ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-06-28 12:00         ` Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Alexander Lakhin <exclusion@gmail.com>
  2026-09-02 01:47           ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-09-02 05:15             ` Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
  2026-09-02 05:42               ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-10-20 15:08                 ` Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Fujii Masao <masao.fujii@gmail.com>
@ 2026-10-21 06:37                   ` Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-10-22 00:32                     ` Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Fujii Masao <masao.fujii@gmail.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Hayato Kuroda (Fujitsu) @ 2026-10-21 06:37 UTC (permalink / raw)
  To: Fujii Masao <masao.fujii@gmail.com>; +Cc: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; pgsql-hackers; Alexander Lakhin <exclusion@gmail.com>

Hi Fujii-san,

> I've started reviewing this patch since it's marked as ready for committer.

Thanks!

> + my $pump_timeout =
> +   IPC::Run::timer($PostgreSQL::Test::Utils::timeout_default);
> 
> This timer is never started or passed to IPC::Run::start(), so it seems
> it can never expire. Right? If so, isn't it better to reuse the existing
> timeout for pump_until()?

I referred the existing code in the same file, like [1].
But you seem right - perl doc [2] describes start() can register a timer object
to the harness and starts it, pump() checks the result. pump() internally calls
start() but calling it alone is not enough because timer must be registered.

It meant existing codes might also be fixed, right?

> + ok(pump_until($slot_user_handle, $pump_timeout, $to_stderr,
> +   qr/streaming initiated/),
> +    "pg_recvlogical started streaming");
> 
> This allows the test to continue even if pump_until() returns false.
> Since streaming is a prerequisite for the subsequent steps, we should
> use or die(), as the old code did?

+1.

> I also found a pre-existing typo: the slots are created with the prefix
> "drop_db_", but their removal is checked using "drop_db". Since
> those names never existed, the checks pass even if the actual slots
> remain. Attached 0002 fixes this.

Good catch, LGTM.

[1]
```
# check that we are decoding pre and post promotion inserted rows
# with pg_recvlogical that has started before the promotion
my $pump_timeout = IPC::Run::timer($PostgreSQL::Test::Utils::timeout_default);

ok(pump_until($handle, $pump_timeout, \$stdout, qr/^.*COMMIT.*COMMIT$/s),
	'got 2 COMMIT from pg_recvlogical output');
```
[2]: https://metacpan.org/pod/IPC::Run

Best regards,
Hayato Kuroda
FUJITSU LIMITED 



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq
  2026-05-17 15:00 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Alexander Lakhin <exclusion@gmail.com>
  2026-05-27 05:43 ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-05-27 17:00   ` Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Alexander Lakhin <exclusion@gmail.com>
  2026-06-24 14:12     ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-06-25 02:04       ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-06-28 12:00         ` Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Alexander Lakhin <exclusion@gmail.com>
  2026-09-02 01:47           ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-09-02 05:15             ` Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
  2026-09-02 05:42               ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
  2026-10-20 15:08                 ` Re: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Fujii Masao <masao.fujii@gmail.com>
  2026-10-21 06:37                   ` RE: 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
@ 2026-10-22 00:32                     ` Fujii Masao <masao.fujii@gmail.com>
  0 siblings, 0 replies; 12+ messages in thread

From: Fujii Masao @ 2026-10-22 00:32 UTC (permalink / raw)
  To: Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>; +Cc: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>; pgsql-hackers; Alexander Lakhin <exclusion@gmail.com>

On Wed, Oct 21, 2026 at 3:37 PM Hayato Kuroda (Fujitsu)
<kuroda.hayato@fujitsu.com> wrote:
> It meant existing codes might also be fixed, right?

Yes, probably. I haven't looked at the referenced code in detail yet, though..

> Good catch, LGTM.

Thanks for the review! I've pushed the patches.

Regards,

-- 
Fujii Masao






^ permalink  raw  reply  [nested|flat] 12+ messages in thread


end of thread, other threads:[~2026-10-22 00:32 UTC | newest]

Thread overview: 12+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-05-17 15:00 035_standby_logical_decoding might fail due to FATAL message lost inside libpq Alexander Lakhin <exclusion@gmail.com>
2026-05-27 05:43 ` Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
2026-05-27 17:00   ` Alexander Lakhin <exclusion@gmail.com>
2026-06-24 14:12     ` Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
2026-06-25 02:04       ` Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
2026-06-28 12:00         ` Alexander Lakhin <exclusion@gmail.com>
2026-09-02 01:47           ` Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
2026-09-02 05:15             ` Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
2026-09-02 05:42               ` Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
2026-10-20 15:08                 ` Fujii Masao <masao.fujii@gmail.com>
2026-10-21 06:37                   ` Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
2026-10-22 00:32                     ` Fujii Masao <masao.fujii@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox