From c1d6ee879285969a93f244e08a3ff2344d2cd7ff Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 4 Aug 2016 16:06:14 -0400 Subject: [PATCH] Fix bogus coding in WaitForBackgroundWorkerShutdown(). Some conditions resulted in "return" directly out of a PG_TRY block, which left the exception stack dangling, and to add insult to injury failed to restore the state of set_latch_on_sigusr1. This is a bug only in 9.5; in HEAD it was accidentally fixed by commit db0f6cad4, which removed the surrounding PG_TRY block. However, I (tgl) chose to apply the patch to HEAD as well, because the old coding was gratuitously different from WaitForBackgroundWorkerStartup(), and there would indeed have been no bug if it were done like that to start with. Dmitry Ivanov Discussion: <1637882.WfYN5gPf1A@abook> --- src/backend/postmaster/bgworker.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/backend/postmaster/bgworker.c b/src/backend/postmaster/bgworker.c index 76619e9517c..fd552626684 100644 --- a/src/backend/postmaster/bgworker.c +++ b/src/backend/postmaster/bgworker.c @@ -1025,13 +1025,16 @@ WaitForBackgroundWorkerShutdown(BackgroundWorkerHandle *handle) status = GetBackgroundWorkerPid(handle, &pid); if (status == BGWH_STOPPED) - return status; + break; rc = WaitLatch(&MyProc->procLatch, WL_LATCH_SET | WL_POSTMASTER_DEATH, 0); if (rc & WL_POSTMASTER_DEATH) - return BGWH_POSTMASTER_DIED; + { + status = BGWH_POSTMASTER_DIED; + break; + } ResetLatch(&MyProc->procLatch); }