1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-05 02:22:28 +03:00

Don't run atexit callbacks during signal exits from ProcessStartupPacket.

Although 58c6feccf fixed the case for SIGQUIT, we were still calling
proc_exit() from signal handlers for SIGTERM and timeout failures in
ProcessStartupPacket.  Fortunately, at the point where that code runs,
we haven't yet connected to shared memory in any meaningful way, so
there is nothing we need to undo in shared memory.  This means it
should be safe to use _exit(1) here, ie, not run any atexit handlers
but also inform the postmaster that it's not a crash exit.

To make sure nobody breaks the "nothing to undo" expectation, add
a cross-check that no on-shmem-exit or before-shmem-exit handlers
have been registered yet when we finish using these signal handlers.

This change is simple enough that maybe it could be back-patched,
but I won't risk that right now.

Discussion: https://postgr.es/m/1850884.1599601164@sss.pgh.pa.us
This commit is contained in:
Tom Lane
2020-09-11 12:20:16 -04:00
parent 6a68a233ce
commit 6693a96b32
3 changed files with 51 additions and 39 deletions

View File

@@ -416,3 +416,20 @@ on_exit_reset(void)
on_proc_exit_index = 0;
reset_on_dsm_detach();
}
/* ----------------------------------------------------------------
* check_on_shmem_exit_lists_are_empty
*
* Debugging check that no shmem cleanup handlers have been registered
* prematurely in the current process.
* ----------------------------------------------------------------
*/
void
check_on_shmem_exit_lists_are_empty(void)
{
if (before_shmem_exit_index)
elog(FATAL, "before_shmem_exit has been called prematurely");
if (on_shmem_exit_index)
elog(FATAL, "on_shmem_exit has been called prematurely");
/* Checking DSM detach state seems unnecessary given the above */
}