Skip to content

Commit bcd5b4b

Browse files
Fix crash in autoprewarm.
Commit abb0b4f moved the shared state for autoprewarm to a dynamic shared memory (DSM) segment, but it left apw_detach_shmem() in the on_shmem_exit callback list for the autoprewarm leader process. This is a problem because shmem_exit() detaches all the DSM segments prior to calling the on_shmem_exit callbacks, thus producing segfaults in the exit path for the autoprewarm leader process. To fix, move apw_detach_shmem() to the before_shmem_exit callback list. This commit also adds a check to pg_prewarm's test that the server shut down normally. It might be worth making this a common check for all shutdowns in TAP tests, but that is left as a future exercise. Reported-by: Andres Freund Reviewed-by: Andres Freund, Álvaro Herrera Discussion: https://postgr.es/m/20240122204117.swton324xcoodnyi%40awork3.anarazel.de
1 parent 79b03db commit bcd5b4b

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

contrib/pg_prewarm/autoprewarm.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,14 @@ autoprewarm_main(Datum main_arg)
164164
if (apw_init_shmem())
165165
first_time = false;
166166

167-
/* Set on-detach hook so that our PID will be cleared on exit. */
168-
on_shmem_exit(apw_detach_shmem, 0);
167+
/*
168+
* Set on-detach hook so that our PID will be cleared on exit.
169+
*
170+
* NB: Autoprewarm's state is stored in a DSM segment, and DSM segments
171+
* are detached before calling the on_shmem_exit callbacks, so we must put
172+
* apw_detach_shmem in the before_shmem_exit callback list.
173+
*/
174+
before_shmem_exit(apw_detach_shmem, 0);
169175

170176
/*
171177
* Store our PID in the shared memory area --- unless there's already

contrib/pg_prewarm/t/001_basic.pl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,10 @@
5555

5656
$node->stop;
5757

58+
# control file should indicate normal shut down
59+
command_like(
60+
[ 'pg_controldata', $node->data_dir() ],
61+
qr/Database cluster state:\s*shut down/,
62+
'cluster shut down normally');
63+
5864
done_testing();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy