041_checkpoint_at_promote.pl might fail due to race condition on child kill
041_checkpoint_at_promote.pl might fail due to race condition on child kill
От:
Alexander Lakhin <exclusion@gmail.com>
Дата:
Hello hackers,
Please look at a new failure of 041_checkpoint_at_promote.pl produced by
bushmaster, [1]:
[23:56:13.841](0.002s) ok 4 - psql query died successfully after SIGKILL
[23:56:13.902](0.061s) not ok 5 - psql connect success
[23:56:13.902](0.000s)
[23:56:13.902](0.000s) # Failed test 'psql connect success'
# at t/041_checkpoint_at_promote.pl line 168.
[23:56:13.902](0.000s) # got: '2'
# expected: '0'
[23:56:13.902](0.000s) not ok 6 - psql select 1
[23:56:13.902](0.000s)
[23:56:13.902](0.000s) # Failed test 'psql select 1'
# at t/041_checkpoint_at_promote.pl line 169.
[23:56:13.902](0.000s) # got: ''
# expected: '1'
[23:56:13.902](0.000s) 1..6
pgsql.build/src/test/recovery/tmp_check/log/041_checkpoint_at_promote_standby1.log
2026-10-03 23:56:13.852 CEST [4159149][postmaster][:0] LOG: client backend (PID 4159398) was terminated by signal 9: Killed
2026-10-03 23:56:13.852 CEST [4159149][postmaster][:0] DETAIL: Failed process was running: SELECT pg_backend_pid();
2026-10-03 23:56:13.852 CEST [4159149][postmaster][:0] LOG: terminating any other active server processes
2026-10-03 23:56:13.855 CEST [4159149][postmaster][:0] LOG: all server processes terminated; reinitializing
2026-10-03 23:56:13.899 CEST [4159414][startup][:0] LOG: database system was interrupted; last known up at 2026-10-03
23:56:13 CEST
2026-10-03 23:56:13.899 CEST [4159414][startup][:0] LOG: database system was not properly shut down; automatic recovery
in progress
2026-10-03 23:56:13.899 CEST [4159414][startup][:0] LOG: crash recovery starts in timeline 1 and has target timeline 2
2026-10-03 23:56:13.900 CEST [4159414][startup][:0] LOG: redo starts at 0/3000028
2026-10-03 23:56:13.900 CEST [4159417][not initialized][:0] LOG: connection received: host=[local]
2026-10-03 23:56:13.900 CEST [4159417][client backend][:0] FATAL: the database system is in recovery mode
I've reproduced this failure locally, running multiple tests concurrently inside a 4-core VM, in a loop:
for i in {1..50}; do echo "Iteration $i"; parallel -j40 --linebuffer --tag PROVE_TESTS="t/041*" NO_TEMP_INSTALL=1
TEMP_CONFIG=~/extra.config make -s check -s -C src/test/recovery_{} PROVE_FLAGS="--timer" ::: `seq 25` || break; done;
(with bushmaster's parameters put in ~/extra.config)
This failed for me on iterations 14, 30, 10:
...
Iteration 10
...
10
10 # Failed test 'psql connect success'
10 # at t/041_checkpoint_at_promote.pl line 168.
10 # got: '2'
10 # expected: '0'
10
10 # Failed test 'psql select 1'
10 # at t/041_checkpoint_at_promote.pl line 169.
10 # got: ''
10 # expected: '1'
10 # Looks like you failed 2 tests of 6.
10 [03:51:18] t/041_checkpoint_at_promote.pl ..
10 Dubious, test returned 2 (wstat 512, 0x200)
10 Failed 2/6 subtests
10 [03:51:18]
10
10 Test Summary Report
10 -------------------
10 t/041_checkpoint_at_promote.pl (Wstat: 512 (exited 2) Tests: 6 Failed: 2)
10 Failed tests: 5-6
10 Non-zero exit status: 2
It looks like the same race condition was fixed in 022_crash_temp_files.pl
by e37ad5fa4 two years before 041_checkpoint_at_promote.pl appeared: [2].
[1] https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=bushmaster&dt=2026-10-03%2021%3A37%3A08
[2] https://postgr.es/m/1801850.1649047827@sss.pgh.pa.us
Best regards,
Alexander
Re: 041_checkpoint_at_promote.pl might fail due to race condition on child kill
On Wed, Oct 7, 2026 at 1:00 PM Alexander Lakhin wrote: > It looks like the same race condition was fixed in 022_crash_temp_files.pl > by e37ad5fa4 two years before 041_checkpoint_at_promote.pl appeared: [2]. I tried creating the patch based on that fix. How about the attached patch? Regards, -- Fujii Masao
Re: 041_checkpoint_at_promote.pl might fail due to race condition on child kill
От:
Alexander Lakhin <exclusion@gmail.com>
Дата:
Hello Fujii-san,
07.10.2026 19:46, Fujii Masao wrote:
07.10.2026 19:46, Fujii Masao wrote:
On Wed, Oct 7, 2026 at 1:00 PM Alexander Lakhin <exclusion@gmail.com> wrote:It looks like the same race condition was fixed in 022_crash_temp_files.pl by e37ad5fa4 two years before 041_checkpoint_at_promote.pl appeared: [2].I tried creating the patch based on that fix. How about the attached patch?
Your patch works for me test-wise. The same test loop passed 100+
iterations successfully. Thank you for paying attention to this!
Best regards,
Alexander
Re: 041_checkpoint_at_promote.pl might fail due to race condition on child kill
On Fri, Oct 9, 2026 at 4:00 AM Alexander Lakhin wrote: > Your patch works for me test-wise. The same test loop passed 100+ > iterations successfully. Thank you for paying attention to this! Thanks for the test! On second thought, we can simplify the test by waiting for the postmaster to log "all server processes terminated; reinitializing" instead of using another backend connection to detect the crash. This ensures that the postmaster has detected the crash and started restarting. The attached patch takes this approach. Thoughts? Regards, -- Fujii Masao
Re: 041_checkpoint_at_promote.pl might fail due to race condition on child kill
От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Tue, Oct 13, 2026 at 4:17 PM Fujii Masao wrote: > On second thought, we can simplify the test by waiting for the postmaster to > log "all server processes terminated; reinitializing" instead of using > another backend connection to detect the crash. This ensures that the > postmaster has detected the crash and started restarting. The attached > patch takes this approach. Thoughts? Barring any objections, I will commit this patch. Regards, -- Fujii Masao
Re: 041_checkpoint_at_promote.pl might fail due to race condition on child kill
От:
Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Дата:
Hi, On Tue, 13 Oct 2026 at 12:47, Fujii Masao wrote: > > On Fri, Oct 9, 2026 at 4:00 AM Alexander Lakhin wrote: > > Your patch works for me test-wise. The same test loop passed 100+ > > iterations successfully. Thank you for paying attention to this! > > Thanks for the test! > > On second thought, we can simplify the test by waiting for the postmaster to > log "all server processes terminated; reinitializing" instead of using > another backend connection to detect the crash. This ensures that the > postmaster has detected the crash and started restarting. The attached > patch takes this approach. Thoughts? Thanks for the patch. Did multiple runs with it, and the changes lgtm. Regards, Ayush
Re: 041_checkpoint_at_promote.pl might fail due to race condition on child kill
От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Fri, Oct 30, 2026 at 3:59 PM Ayush Tiwari wrote: > Did multiple runs with it, and the changes lgtm. I've pushed the patch. Thanks! Regards, -- Fujii Masao
Re: 041_checkpoint_at_promote.pl might fail due to race condition on child kill
Hello Fujii-san and Ayush, 30.10.2026 13:55, Fujii Masao wrote: > On Fri, Oct 30, 2026 at 3:59 PM Ayush Tiwari > wrote: >> Did multiple runs with it, and the changes lgtm. > I've pushed the patch. Thanks! Please look at a new failure of 041_checkpoint_at_promote produced by tamandua recently [1]: [03:10:10.869](0.025s) ok 4 - psql query died successfully after SIGKILL [03:13:15.804](184.935s) # die: timed out waiting for file /home/bf/bf-build/tamandua/REL_19_STABLE/pgsql.build/testrun/recovery/041_checkpoint_at_promote/log/041_checkpoint_at_promote_standby1.log contents to match: (?^:all server processes terminated; reinitializing) at /home/bf/bf-build/tamandua/REL_19_STABLE/pgsql/src/test/recovery/t/041_checkpoint_at_promote.pl line 166. [03:13:15.806](0.003s) 1..4 timed out waiting for file /home/bf/bf-build/tamandua/REL_19_STABLE/pgsql.build/testrun/recovery/041_checkpoint_at_promote/log/041_checkpoint_at_promote_standby1.log contents to match: (?^:all server processes terminated; reinitializing) at /home/bf/bf-build/tamandua/REL_19_STABLE/pgsql/src/test/recovery/t/041_checkpoint_at_promote.pl line 166. # No postmaster PID for node "master" 041_checkpoint_at_promote_standby1.log contains: 2026-11-12 03:10:10.826 CET [3578531][client backend][6/2:0] LOG: statement: SELECT pg_backend_pid(); 2026-11-12 03:10:10.861 CET [3577203][postmaster][:0] LOG: client backend (PID 3578531) was terminated by signal 9: Killed 2026-11-12 03:10:10.861 CET [3577203][postmaster][:0] DETAIL: Failed process was running: SELECT pg_backend_pid(); 2026-11-12 03:10:10.862 CET [3577203][postmaster][:0] LOG: terminating any other active server processes 2026-11-12 03:10:10.928 CET [3577203][postmaster][:0] LOG: database system is ready to accept connections There is no "terminating any other active server processes" message indeed, the server was not shut down. I managed to reproduce this locally (with the patch attached and with the same parallel loop as before) and discovered that this can happen when PMState goes from PM_HOT_STANDBY to PM_RUN (via PM_WAIT_BACKENDS) instead of PM_HOT_STANDBY -> PM_WAIT_BACKENDS -> PM_WAIT_DEAD_END -> PM_NO_CHILDREN -> "all server processes terminated; reinitializing". This can be explained by two race conditions, with one precondition: the startup process doesn't exit before pg_ctl kill. 1) The startup process becomes zombie for the postmaster if it exits when waitpid() doesn't wait. ... 2026-11-14 13:29:02.900 UTC [695404][startup][:0] DEBUG: proc_exit(-1): 0 callbacks to make ... 2026-11-14 13:29:03.088 UTC [695367][postmaster][:0] DEBUG: sending signal 3/SIGQUIT to startup process with pid 695404 2026-11-14 13:29:03.100 UTC [695367][postmaster][:0] LOG: !!!signal_child| delayed signal 3/SIGQUIT to startup process with pid 695404 ... 2026-11-14 13:29:03.170 UTC [695367][postmaster][:0] DEBUG: startup process 695404 is still running ... 2026-11-14 13:29:03.198 UTC [695367][postmaster][:0] DEBUG: updating PMState from PM_WAIT_BACKENDS to PM_RUN 2) SIGQUIT sent to the startup process when it's being executed inside exit(0), after the point when signal handlers of a process are not called anymore, so SIGQUIT is ignored: ... 2026-11-14 07:54:44.900 EST [1110043][startup][:0] LOG: !!!proc_exit| delayed exit(0) for startup process ... 2026-11-14 07:54:44.900 EST [1110043][startup][:0] DEBUG: proc_exit(-1): 0 callbacks to make 2026-11-14 07:54:44.900 EST [1110037][postmaster][:0] LOG: !!!signal_child| delayed signal 3/SIGQUIT to startup process with pid 1110043 ... 2026-11-14 07:54:44.900 EST [1110037][postmaster][:0] DEBUG: startup process 1110043 is still running ... 2026-11-14 07:54:44.903 EST [1110037][postmaster][:0] LOG: !!!waitpid| ret: 1110043, status: 0 2026-11-14 07:54:44.903 EST [1110037][postmaster][:0] DEBUG: releasing pm child slot 89 2026-11-14 07:54:44.903 EST [1110037][postmaster][:0] DEBUG: updating PMState from PM_WAIT_BACKENDS to PM_RUN Corresponding logs for these 2 cases and also a normal run's log are attached for reference. [1] https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=tamandua&dt=2026-11-12%2002%3A04%3A37 Best regards, Alexander
Re: 041_checkpoint_at_promote.pl might fail due to race condition on child kill
От:
Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Дата:
Hi,
On Sat, 14 Nov 2026 at 19:30, Alexander Lakhin <exclusion@gmail.com> wrote:
>
> Hello Fujii-san and Ayush,
>
> 30.10.2026 13:55, Fujii Masao wrote:
> > On Fri, Oct 30, 2026 at 3:59 PM Ayush Tiwari
> > <ayushtiwari.slg01@gmail.com> wrote:
> >> Did multiple runs with it, and the changes lgtm.
> > I've pushed the patch. Thanks!
>
> Please look at a new failure of 041_checkpoint_at_promote produced by
> tamandua recently [1]:
> [03:10:10.869](0.025s) ok 4 - psql query died successfully after SIGKILL
> [03:13:15.804](184.935s) # die: timed out waiting for file
> /home/bf/bf-build/tamandua/REL_19_STABLE/pgsql.build/testrun/recovery/041_checkpoint_at_promote/log/041_checkpoint_at_promote_standby1.log
> contents to match: (?^:all server processes terminated; reinitializing) at
> /home/bf/bf-build/tamandua/REL_19_STABLE/pgsql/src/test/recovery/t/041_checkpoint_at_promote.pl line 166.
> [03:13:15.806](0.003s) 1..4
> timed out waiting for file
> /home/bf/bf-build/tamandua/REL_19_STABLE/pgsql.build/testrun/recovery/041_checkpoint_at_promote/log/041_checkpoint_at_promote_standby1.log
> contents to match: (?^:all server processes terminated; reinitializing) at
> /home/bf/bf-build/tamandua/REL_19_STABLE/pgsql/src/test/recovery/t/041_checkpoint_at_promote.pl line 166.
> # No postmaster PID for node "master"
>
> 041_checkpoint_at_promote_standby1.log contains:
> 2026-11-12 03:10:10.826 CET [3578531][client backend][6/2:0] LOG: statement: SELECT pg_backend_pid();
> 2026-11-12 03:10:10.861 CET [3577203][postmaster][:0] LOG: client backend (PID 3578531) was terminated by signal 9: Killed
> 2026-11-12 03:10:10.861 CET [3577203][postmaster][:0] DETAIL: Failed process was running: SELECT pg_backend_pid();
> 2026-11-12 03:10:10.862 CET [3577203][postmaster][:0] LOG: terminating any other active server processes
> 2026-11-12 03:10:10.928 CET [3577203][postmaster][:0] LOG: database system is ready to accept connections
>
> There is no "terminating any other active server processes" message
> indeed, the server was not shut down.
>
> I managed to reproduce this locally (with the patch attached and with the
> same parallel loop as before) and discovered that this can happen when
> PMState goes from PM_HOT_STANDBY to PM_RUN (via PM_WAIT_BACKENDS) instead
> of PM_HOT_STANDBY -> PM_WAIT_BACKENDS -> PM_WAIT_DEAD_END ->
> PM_NO_CHILDREN -> "all server processes terminated; reinitializing".
>
> This can be explained by two race conditions, with one precondition: the
> startup process doesn't exit before pg_ctl kill.
> 1) The startup process becomes zombie for the postmaster if it exits when
> waitpid() doesn't wait.
> ...
> 2026-11-14 13:29:02.900 UTC [695404][startup][:0] DEBUG: proc_exit(-1): 0 callbacks to make
> ...
> 2026-11-14 13:29:03.088 UTC [695367][postmaster][:0] DEBUG: sending signal 3/SIGQUIT to startup process with pid 695404
> 2026-11-14 13:29:03.100 UTC [695367][postmaster][:0] LOG: !!!signal_child| delayed signal 3/SIGQUIT to startup process
> with pid 695404
> ...
> 2026-11-14 13:29:03.170 UTC [695367][postmaster][:0] DEBUG: startup process 695404 is still running
> ...
> 2026-11-14 13:29:03.198 UTC [695367][postmaster][:0] DEBUG: updating PMState from PM_WAIT_BACKENDS to PM_RUN
>
>
> 2) SIGQUIT sent to the startup process when it's being executed inside
> exit(0), after the point when signal handlers of a process are not called
> anymore, so SIGQUIT is ignored:
> ...
> 2026-11-14 07:54:44.900 EST [1110043][startup][:0] LOG: !!!proc_exit| delayed exit(0) for startup process
> ...
> 2026-11-14 07:54:44.900 EST [1110043][startup][:0] DEBUG: proc_exit(-1): 0 callbacks to make
> 2026-11-14 07:54:44.900 EST [1110037][postmaster][:0] LOG: !!!signal_child| delayed signal 3/SIGQUIT to startup process
> with pid 1110043
> ...
> 2026-11-14 07:54:44.900 EST [1110037][postmaster][:0] DEBUG: startup process 1110043 is still running
> ...
> 2026-11-14 07:54:44.903 EST [1110037][postmaster][:0] LOG: !!!waitpid| ret: 1110043, status: 0
> 2026-11-14 07:54:44.903 EST [1110037][postmaster][:0] DEBUG: releasing pm child slot 89
> 2026-11-14 07:54:44.903 EST [1110037][postmaster][:0] DEBUG: updating PMState from PM_WAIT_BACKENDS to PM_RUN
>
> Corresponding logs for these 2 cases and also a normal run's log are
> attached for reference.
Thanks, I reproduced this with your debugging patch. Looks like a
postmaster bug rather than a problem with the test. Let me try to
write here what I understood.
Normally, startup exits with status 0 after promotion, and the postmaster
takes that as the signal to enter PM_RUN. A backend crash needs the
opposite, stop the other children and rebuild shared memory before
letting the server run again.
Here those two things happen at almost the same time:
1) Startup finishes promotion and is exiting, but the postmaster hasn't
collected its exit status yet.
2) The test kills a backend. The postmaster notices that death first,
sets FatalError and sends SIGQUIT to the remaining children. It recrds
that it told startup to quit by setting STARTUP_SIGNALED.
3) SIGQUIT is too late for startup, it has already exited, or is too far
into exit(0) to handle it? Its exit status is basically still 0.
4) The postmaster then collects that 0 and takes the normal "startup
succeeded" path. It clears FatalError and enters PM_RUN, skipping the
shared-memory reset needed for the backend crash.
That's why the test never sees "all server processes terminated;
reinitializing".
I think we should check STARTUP_SIGNALED even when the exit status is 0.
Something like [2]. With that diff, I tried your patch and reran the tests multiple
times and it all passed.
Regards,
Ayush
> [1] https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=tamandua&dt=2026-11-12%2002%3A04%3A37
[2]
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index f53aa9c404d..a2e52b61902 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -2317,12 +2317,13 @@ process_pm_child_exit(void)
* during PM_STARTUP due to some dead-end child crashing: in that
* situation, if the startup process dies on the SIGQUIT, we need
* to transition to PM_WAIT_BACKENDS state which will allow
- * PostmasterStateMachine to restart the startup process. (On the
- * other hand, the startup process might complete normally, if we
- * were too late with the SIGQUIT. In that case we'll fall
- * through and commence normal operations.)
+ * PostmasterStateMachine to restart the startup process.
+ *
+ * SIGQUIT may arrive too late to change the startup process's exit
+ * status. If we signaled it, continue the crash restart even if it
+ * exits normally.
*/
- if (!EXIT_STATUS_0(exitstatus))
+ if (!EXIT_STATUS_0(exitstatus) || StartupStatus == STARTUP_SIGNALED)
{
if (StartupStatus == STARTUP_SIGNALED)
{
On Sat, 14 Nov 2026 at 19:30, Alexander Lakhin <exclusion@gmail.com> wrote:
>
> Hello Fujii-san and Ayush,
>
> 30.10.2026 13:55, Fujii Masao wrote:
> > On Fri, Oct 30, 2026 at 3:59 PM Ayush Tiwari
> > <ayushtiwari.slg01@gmail.com> wrote:
> >> Did multiple runs with it, and the changes lgtm.
> > I've pushed the patch. Thanks!
>
> Please look at a new failure of 041_checkpoint_at_promote produced by
> tamandua recently [1]:
> [03:10:10.869](0.025s) ok 4 - psql query died successfully after SIGKILL
> [03:13:15.804](184.935s) # die: timed out waiting for file
> /home/bf/bf-build/tamandua/REL_19_STABLE/pgsql.build/testrun/recovery/041_checkpoint_at_promote/log/041_checkpoint_at_promote_standby1.log
> contents to match: (?^:all server processes terminated; reinitializing) at
> /home/bf/bf-build/tamandua/REL_19_STABLE/pgsql/src/test/recovery/t/041_checkpoint_at_promote.pl line 166.
> [03:13:15.806](0.003s) 1..4
> timed out waiting for file
> /home/bf/bf-build/tamandua/REL_19_STABLE/pgsql.build/testrun/recovery/041_checkpoint_at_promote/log/041_checkpoint_at_promote_standby1.log
> contents to match: (?^:all server processes terminated; reinitializing) at
> /home/bf/bf-build/tamandua/REL_19_STABLE/pgsql/src/test/recovery/t/041_checkpoint_at_promote.pl line 166.
> # No postmaster PID for node "master"
>
> 041_checkpoint_at_promote_standby1.log contains:
> 2026-11-12 03:10:10.826 CET [3578531][client backend][6/2:0] LOG: statement: SELECT pg_backend_pid();
> 2026-11-12 03:10:10.861 CET [3577203][postmaster][:0] LOG: client backend (PID 3578531) was terminated by signal 9: Killed
> 2026-11-12 03:10:10.861 CET [3577203][postmaster][:0] DETAIL: Failed process was running: SELECT pg_backend_pid();
> 2026-11-12 03:10:10.862 CET [3577203][postmaster][:0] LOG: terminating any other active server processes
> 2026-11-12 03:10:10.928 CET [3577203][postmaster][:0] LOG: database system is ready to accept connections
>
> There is no "terminating any other active server processes" message
> indeed, the server was not shut down.
>
> I managed to reproduce this locally (with the patch attached and with the
> same parallel loop as before) and discovered that this can happen when
> PMState goes from PM_HOT_STANDBY to PM_RUN (via PM_WAIT_BACKENDS) instead
> of PM_HOT_STANDBY -> PM_WAIT_BACKENDS -> PM_WAIT_DEAD_END ->
> PM_NO_CHILDREN -> "all server processes terminated; reinitializing".
>
> This can be explained by two race conditions, with one precondition: the
> startup process doesn't exit before pg_ctl kill.
> 1) The startup process becomes zombie for the postmaster if it exits when
> waitpid() doesn't wait.
> ...
> 2026-11-14 13:29:02.900 UTC [695404][startup][:0] DEBUG: proc_exit(-1): 0 callbacks to make
> ...
> 2026-11-14 13:29:03.088 UTC [695367][postmaster][:0] DEBUG: sending signal 3/SIGQUIT to startup process with pid 695404
> 2026-11-14 13:29:03.100 UTC [695367][postmaster][:0] LOG: !!!signal_child| delayed signal 3/SIGQUIT to startup process
> with pid 695404
> ...
> 2026-11-14 13:29:03.170 UTC [695367][postmaster][:0] DEBUG: startup process 695404 is still running
> ...
> 2026-11-14 13:29:03.198 UTC [695367][postmaster][:0] DEBUG: updating PMState from PM_WAIT_BACKENDS to PM_RUN
>
>
> 2) SIGQUIT sent to the startup process when it's being executed inside
> exit(0), after the point when signal handlers of a process are not called
> anymore, so SIGQUIT is ignored:
> ...
> 2026-11-14 07:54:44.900 EST [1110043][startup][:0] LOG: !!!proc_exit| delayed exit(0) for startup process
> ...
> 2026-11-14 07:54:44.900 EST [1110043][startup][:0] DEBUG: proc_exit(-1): 0 callbacks to make
> 2026-11-14 07:54:44.900 EST [1110037][postmaster][:0] LOG: !!!signal_child| delayed signal 3/SIGQUIT to startup process
> with pid 1110043
> ...
> 2026-11-14 07:54:44.900 EST [1110037][postmaster][:0] DEBUG: startup process 1110043 is still running
> ...
> 2026-11-14 07:54:44.903 EST [1110037][postmaster][:0] LOG: !!!waitpid| ret: 1110043, status: 0
> 2026-11-14 07:54:44.903 EST [1110037][postmaster][:0] DEBUG: releasing pm child slot 89
> 2026-11-14 07:54:44.903 EST [1110037][postmaster][:0] DEBUG: updating PMState from PM_WAIT_BACKENDS to PM_RUN
>
> Corresponding logs for these 2 cases and also a normal run's log are
> attached for reference.
Thanks, I reproduced this with your debugging patch. Looks like a
postmaster bug rather than a problem with the test. Let me try to
write here what I understood.
Normally, startup exits with status 0 after promotion, and the postmaster
takes that as the signal to enter PM_RUN. A backend crash needs the
opposite, stop the other children and rebuild shared memory before
letting the server run again.
Here those two things happen at almost the same time:
1) Startup finishes promotion and is exiting, but the postmaster hasn't
collected its exit status yet.
2) The test kills a backend. The postmaster notices that death first,
sets FatalError and sends SIGQUIT to the remaining children. It recrds
that it told startup to quit by setting STARTUP_SIGNALED.
3) SIGQUIT is too late for startup, it has already exited, or is too far
into exit(0) to handle it? Its exit status is basically still 0.
4) The postmaster then collects that 0 and takes the normal "startup
succeeded" path. It clears FatalError and enters PM_RUN, skipping the
shared-memory reset needed for the backend crash.
That's why the test never sees "all server processes terminated;
reinitializing".
I think we should check STARTUP_SIGNALED even when the exit status is 0.
Something like [2]. With that diff, I tried your patch and reran the tests multiple
times and it all passed.
Regards,
Ayush
> [1] https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=tamandua&dt=2026-11-12%2002%3A04%3A37
[2]
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index f53aa9c404d..a2e52b61902 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -2317,12 +2317,13 @@ process_pm_child_exit(void)
* during PM_STARTUP due to some dead-end child crashing: in that
* situation, if the startup process dies on the SIGQUIT, we need
* to transition to PM_WAIT_BACKENDS state which will allow
- * PostmasterStateMachine to restart the startup process. (On the
- * other hand, the startup process might complete normally, if we
- * were too late with the SIGQUIT. In that case we'll fall
- * through and commence normal operations.)
+ * PostmasterStateMachine to restart the startup process.
+ *
+ * SIGQUIT may arrive too late to change the startup process's exit
+ * status. If we signaled it, continue the crash restart even if it
+ * exits normally.
*/
- if (!EXIT_STATUS_0(exitstatus))
+ if (!EXIT_STATUS_0(exitstatus) || StartupStatus == STARTUP_SIGNALED)
{
if (StartupStatus == STARTUP_SIGNALED)
{
Re: 041_checkpoint_at_promote.pl might fail due to race condition on child kill
От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Mon, Nov 16, 2026 at 2:26 PM Ayush Tiwari wrote: > I think we should check STARTUP_SIGNALED even when the exit status is 0. > Something like [2]. LGTM, thanks! This should be backpatched to all supported versions? Regards, -- Fujii Masao
Re: 041_checkpoint_at_promote.pl might fail due to race condition on child kill
От:
Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Дата:
Hi, On Mon, 16 Nov 2026 at 11:49, Fujii Masao wrote: > > On Mon, Nov 16, 2026 at 2:26 PM Ayush Tiwari > wrote: > > I think we should check STARTUP_SIGNALED even when the exit status is 0. > > Something like [2]. > > LGTM, thanks! Thanks for the review, Fujii-san! > This should be backpatched to all supported versions? Yes, back till 15. Regards, Ayush