Skip to content

Commit e3bf962

Browse files
committed
Shut down transaction tracking at startup process exit.
Maxim Orlov reported that the shutdown of standby server could result in the following assertion failure. The cause of this issue was that, when the shutdown caused the startup process to exit, recovery-time transaction tracking was not shut down even if it's already initialized, and some locks the tracked transactions were holding could not be released. At this situation, if other process was invoked and the PGPROC entry that the startup process used was assigned to it, it found such unreleased locks and caused the assertion failure, during the initialization of it. TRAP: FailedAssertion("SHMQueueEmpty(&(MyProc->myProcLocks[i]))" This commit fixes this issue by making the startup process shut down transaction tracking and release all locks, at the exit of it. Back-patch to all supported branches. Reported-by: Maxim Orlov Author: Fujii Masao Reviewed-by: Maxim Orlov Discussion: https://postgr.es/m/ad4ce692cc1d89a093b471ab1d969b0b@postgrespro.ru
1 parent 605ef23 commit e3bf962

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/backend/postmaster/startup.c

+19
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ static void StartupProcSigUsr1Handler(SIGNAL_ARGS);
5353
static void StartupProcTriggerHandler(SIGNAL_ARGS);
5454
static void StartupProcSigHupHandler(SIGNAL_ARGS);
5555

56+
/* Callbacks */
57+
static void StartupProcExit(int code, Datum arg);
58+
5659

5760
/* --------------------------------
5861
* signal handler routines
@@ -164,13 +167,29 @@ HandleStartupProcInterrupts(void)
164167
}
165168

166169

170+
/* --------------------------------
171+
* signal handler routines
172+
* --------------------------------
173+
*/
174+
static void
175+
StartupProcExit(int code, Datum arg)
176+
{
177+
/* Shutdown the recovery environment */
178+
if (standbyState != STANDBY_DISABLED)
179+
ShutdownRecoveryTransactionEnvironment();
180+
}
181+
182+
167183
/* ----------------------------------
168184
* Startup Process main entry point
169185
* ----------------------------------
170186
*/
171187
void
172188
StartupProcessMain(void)
173189
{
190+
/* Arrange to clean up at startup process exit */
191+
on_shmem_exit(StartupProcExit, 0);
192+
174193
/*
175194
* Properly accept or ignore signals the postmaster might send us.
176195
*/

src/backend/storage/ipc/standby.c

+15
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,25 @@ InitRecoveryTransactionEnvironment(void)
123123
*
124124
* Prepare to switch from hot standby mode to normal operation. Shut down
125125
* recovery-time transaction tracking.
126+
*
127+
* This must be called even in shutdown of startup process if transaction
128+
* tracking has been initialized. Otherwise some locks the tracked
129+
* transactions were holding will not be released and and may interfere with
130+
* the processes still running (but will exit soon later) at the exit of
131+
* startup process.
126132
*/
127133
void
128134
ShutdownRecoveryTransactionEnvironment(void)
129135
{
136+
/*
137+
* Do nothing if RecoveryLockLists is NULL because which means that
138+
* transaction tracking has not been yet initialized or has been already
139+
* shutdowned. This prevents transaction tracking from being shutdowned
140+
* unexpectedly more than once.
141+
*/
142+
if (RecoveryLockLists == NULL)
143+
return;
144+
130145
/* Mark all tracked in-progress transactions as finished. */
131146
ExpireAllKnownAssignedTransactionIds();
132147

0 commit comments

Comments
 (0)