030_pg_recvlogical fails because the same PID is assigned

Started by Hayato Kuroda (Fujitsu)4 months ago7 messageshackers
Jump to latest
#1Hayato Kuroda (Fujitsu)
kuroda.hayato@fujitsu.com

Hi hackers,

There was a random buildfarm failure for 030_pg_recvlogical [1]https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=fairywren&dt=2026-07-30%2009%3A58%3A12.

It tests that pg_recvlogical can re connect to the server if it the connection is
lost. And we try to ensure by motnitoring the active_pid of the pg_replication_slots
is changed.

According to the logfile in [1]https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=fairywren&dt=2026-07-30%2009%3A58%3A12, the PID of the first walsender was 4360, and
pg_terminate_backend() was done toward it. But while waiting a slot was acquired
by the different process, another walsender whose PID was 4360 (!) was started
and it acquired the slot. The test finally failed because the slot was not
acquired by the different process.

Not sure, does it indicate some other issues? If no, we can wait log output like
"STATEMENT: START_REPLICATION SLOT "reconnect_test" LOGICAL"
to make the test robust.

[1]: https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=fairywren&dt=2026-07-30%2009%3A58%3A12

Best regards,
Hayato Kuroda
FUJITSU LIMITED

#2Alexander Lakhin
exclusion@gmail.com
In reply to: Hayato Kuroda (Fujitsu) (#1)
Re: 030_pg_recvlogical fails because the same PID is assigned

Hello Kuroda-san,

30.07.2026 17:01, Hayato Kuroda (Fujitsu) weote:

Hi hackers,

There was a random buildfarm failure for 030_pg_recvlogical [1].

It tests that pg_recvlogical can re connect to the server if it the connection is
lost. And we try to ensure by motnitoring the active_pid of the pg_replication_slots
is changed.

According to the logfile in [1], the PID of the first walsender was 4360, and
pg_terminate_backend() was done toward it. But while waiting a slot was acquired
by the different process, another walsender whose PID was 4360 (!) was started
and it acquired the slot. The test finally failed because the slot was not
acquired by the different process.

Thank you for paying attention to the failure!

FWIW, it reminded me of [1]/messages/by-id/4245b0de-9367-c443-8145-7b62b0ab3c41@gmail.com, so reused PIDs on Windows caused us problems
before -- probably if we could somehow force Windows to reuse PIDs more
often, it would help discover other similar anomalies.

[1]: /messages/by-id/4245b0de-9367-c443-8145-7b62b0ab3c41@gmail.com

Best regards,
Alexander

#3Hayato Kuroda (Fujitsu)
kuroda.hayato@fujitsu.com
In reply to: Alexander Lakhin (#2)
RE: 030_pg_recvlogical fails because the same PID is assigned

Dear Alexander,

Thank you for paying attention to the failure!

FWIW, it reminded me of [1], so reused PIDs on Windows caused us problems
before -- probably if we could somehow force Windows to reuse PIDs more
often, it would help discover other similar anomalies.

According to my googling, on linux /proc/sys/kernel/ns_last_pid can be used to
control the PID which is assigned for the next process, but I don't think it a
robust way. And quite unclear for the Windows ;-(.

BTW, here is a patch to fix the issue.

Best regards,
Hayato Kuroda
FUJITSU LIMITED

Attachments:

t253255_3
0001-Make-030_pg_recvlogical-robust.patchapplication/octet-stream; name=0001-Make-030_pg_recvlogical-robust.patchDownload+7-7
#4Fujii Masao
masao.fujii@gmail.com
In reply to: Hayato Kuroda (Fujitsu) (#3)
Re: 030_pg_recvlogical fails because the same PID is assigned

On Fri, Jul 31, 2026 at 6:12 PM Hayato Kuroda (Fujitsu)
<kuroda.hayato@fujitsu.com> wrote:

BTW, here is a patch to fix the issue.

Thanks for the patch!

+$node->wait_for_log(
+ qr/START_REPLICATION SLOT \"reconnect_test\" LOGICAL/,
+ $log_offset);

Could this pattern also match the STATEMENT log entry emitted when
the old walsender is terminated by pg_terminate_backend()? If so,
is it be better to wait for the new slot acquisition instead? For example:

qr/acquired logical replication slot \"reconnect_test\"/,

Regards,

--
Fujii Masao

#5Hayato Kuroda (Fujitsu)
kuroda.hayato@fujitsu.com
In reply to: Fujii Masao (#4)
RE: 030_pg_recvlogical fails because the same PID is assigned

Dear Fujii-san,

Sorry for the late reply, I missed your post.

+$node->wait_for_log(
+ qr/START_REPLICATION SLOT \"reconnect_test\" LOGICAL/,
+ $log_offset);

Could this pattern also match the STATEMENT log entry emitted when
the old walsender is terminated by pg_terminate_backend()?

Good catch, it can be.

If so,
is it be better to wait for the new slot acquisition instead? For example:

qr/acquired logical replication slot \"reconnect_test\"/,

Another way is to check the start position specified by the START_REPLICATION is
advanced, but your approach seems better. PSA new version.

Best regards,
Hayato Kuroda
FUJITSU LIMITED

Attachments:

t253255_5
v2-0001-Make-030_pg_recvlogical-robust.patchapplication/octet-stream; name=v2-0001-Make-030_pg_recvlogical-robust.patchDownload+7-7
#6Fujii Masao
masao.fujii@gmail.com
In reply to: Hayato Kuroda (Fujitsu) (#5)
Re: 030_pg_recvlogical fails because the same PID is assigned

On Thu, Aug 6, 2026 at 2:24 PM Hayato Kuroda (Fujitsu)
<kuroda.hayato@fujitsu.com> wrote:

Another way is to check the start position specified by the START_REPLICATION is
advanced, but your approach seems better. PSA new version.

Thanks for updating the patch!

I made a few minor cosmetic changes and pushed the updated patch.

Regards,

--
Fujii Masao

#7Hayato Kuroda (Fujitsu)
kuroda.hayato@fujitsu.com
In reply to: Fujii Masao (#6)
RE: 030_pg_recvlogical fails because the same PID is assigned

Dear Fujii-san,

Thanks for the push. Till now BF animals say OK. Let's keep watching...

Best regards,
Hayato Kuroda
FUJITSU LIMITED