Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bVH9T-0005Fe-Bg for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Aug 2016 11:49:27 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bVH9S-00087O-Uz for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Aug 2016 11:49:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bVH9R-00086R-Ok for pgsql-hackers@postgresql.org; Thu, 04 Aug 2016 11:49:25 +0000 Received: from newmail.postgrespro.ru ([93.174.131.138] helo=mail.postgrespro.ru) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bVH9O-0003I0-PO for pgsql-hackers@postgresql.org; Thu, 04 Aug 2016 11:49:25 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id B034421C294E for ; Thu, 4 Aug 2016 14:49:21 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru Received: from mail.postgrespro.ru ([127.0.0.1]) by localhost (mail.postgrespro.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 72vbrqzxzmLt for ; Thu, 4 Aug 2016 14:49:21 +0300 (MSK) Received: from abook.localnet (unknown [192.168.27.1]) by mail.postgrespro.ru (Postfix) with ESMTPSA id 73D8B21C2947 for ; Thu, 4 Aug 2016 14:49:21 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1470311361; bh=FWdHgIqBnOmLq6M+9HJC1HtZTOu+jluqRCsLjCgEu8M=; h=From:To:Subject:Date:In-Reply-To:References; b=WiiOz4GQL4r37UPlEertiR7oqHDq/2F5OUtiiwOgJLf3FRpvQ55w79ESzI1QHzlSp HVznrpevowTP+cCyrgT9r7uFt5EqYUuMWWfTxiLFk3GY8u0bsbk/l65U4vVM9HoMYG UTAbIkp99GCdVBeQsbICvIJQ0obXVQfE1e80lFMU= From: Dmitry Ivanov To: pgsql-hackers@postgresql.org Subject: Re: Bug in WaitForBackgroundWorkerShutdown() [REL9_5_STABLE] Date: Thu, 04 Aug 2016 14:47:59 +0300 Message-ID: <1996641.25QjV5kv6m@abook> Organization: Postgres Professional User-Agent: KMail/5.2.3 (Linux/4.6.4-1-ARCH; KDE/5.24.0; x86_64; ; ) In-Reply-To: <1637882.WfYN5gPf1A@abook> References: <1637882.WfYN5gPf1A@abook> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart33447150.RbR265GF6l" Content-Transfer-Encoding: 7Bit X-Pg-Spam-Score: -3.2 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org This is a multi-part message in MIME format. --nextPart33447150.RbR265GF6l Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" > Recently I've encountered a strange crash while calling elog(ERROR, "...") > after the WaitForBackgroundWorkerShutdown() function. It turns out that > _returns_ inside the PG_TRY()..PG_CATCH() block are *highly* undesirable, > since they leave PG_exception_stack pointing to a local struct in a dead > frame, which is an obvious UB. I've attached a patch which fixes this > behavior in the aforementioned function, but there might be more errors > like that elsewhere. Forgot some curly braces, my bad. v2 attached. -- Dmitry Ivanov Postgres Professional: http://www.postgrespro.com Russian Postgres Company --nextPart33447150.RbR265GF6l Content-Disposition: attachment; filename="fix_WaitForBackgroundWorkerShutdown_v2.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="fix_WaitForBackgroundWorkerShutdown_v2.patch" diff --git a/src/backend/postmaster/bgworker.c b/src/backend/postmaster/bgworker.c index 76619e9..fd55262 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); } --nextPart33447150.RbR265GF6l Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers --nextPart33447150.RbR265GF6l--