Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1358466

Browse files
committed
Fix bootstrap.c so that database startup process and bgwriter properly release
LWLocks during a panic exit. This avoids the possible self-deadlock pointed out by Qingqing Zhou. Also, I noted that an error during LoadFreeSpaceMap() or BuildFlatFiles() would result in exit(0) which would leave the postmaster thinking all is well. Added a critical section to ensure such errors don't allow startup to proceed. Backpatched to 8.1. The 8.0 code is a bit different and I'm not sure if the problem exists there; given we've not seen this reported from the field, I'm going to be conservative about backpatching any further.
1 parent e4725e3 commit 1358466

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/backend/bootstrap/bootstrap.c

+24-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.215 2006/05/10 23:18:39 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.216 2006/06/08 23:55:48 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -55,6 +55,7 @@ extern char *optarg;
5555

5656
static void usage(void);
5757
static void bootstrap_signals(void);
58+
static void ShutdownDummyProcess(int code, Datum arg);
5859
static hashnode *AddStr(char *str, int strlength, int mderef);
5960
static Form_pg_attribute AllocateAttribute(void);
6061
static int CompHash(char *str, int len);
@@ -395,6 +396,9 @@ BootstrapMain(int argc, char *argv[])
395396

396397
/* finish setting up bufmgr.c */
397398
InitBufferPoolBackend();
399+
400+
/* register a shutdown callback for LWLock cleanup */
401+
on_shmem_exit(ShutdownDummyProcess, 0);
398402
}
399403

400404
/*
@@ -417,8 +421,14 @@ BootstrapMain(int argc, char *argv[])
417421
case BS_XLOG_STARTUP:
418422
bootstrap_signals();
419423
StartupXLOG();
424+
/*
425+
* These next two functions don't consider themselves critical,
426+
* but we'd best PANIC anyway if they fail.
427+
*/
428+
START_CRIT_SECTION();
420429
LoadFreeSpaceMap();
421430
BuildFlatFiles(false);
431+
END_CRIT_SECTION();
422432
proc_exit(0); /* startup done */
423433

424434
case BS_XLOG_BGWRITER:
@@ -552,6 +562,19 @@ bootstrap_signals(void)
552562
}
553563
}
554564

565+
/*
566+
* Begin shutdown of a dummy process. This is approximately the equivalent
567+
* of ShutdownPostgres() in postinit.c. We can't run transactions in a
568+
* dummy process, so most of the work of AbortTransaction() is not needed,
569+
* but we do need to make sure we've released any LWLocks we are holding.
570+
* (This is only critical during an error exit.)
571+
*/
572+
static void
573+
ShutdownDummyProcess(int code, Datum arg)
574+
{
575+
LWLockReleaseAll();
576+
}
577+
555578
/* ----------------
556579
* error handling / abort routines
557580
* ----------------

0 commit comments

Comments
 (0)