Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bVH5p-0005AH-MD for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Aug 2016 11:45:42 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bVH5o-0006SJ-Kf for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Aug 2016 11:45:40 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bVH5n-0006S3-S7 for pgsql-hackers@postgresql.org; Thu, 04 Aug 2016 11:45:40 +0000 Received: from newmail.postgrespro.ru ([93.174.131.138] helo=mail.postgrespro.ru) by makus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bVH5g-00011A-6G for pgsql-hackers@postgresql.org; Thu, 04 Aug 2016 11:45:38 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 4B3A121C2947 for ; Thu, 4 Aug 2016 14:45:31 +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 JeCSzUF2SGvE for ; Thu, 4 Aug 2016 14:45:31 +0300 (MSK) Received: from abook.localnet (unknown [192.168.27.1]) by mail.postgrespro.ru (Postfix) with ESMTPSA id 235B221C2909 for ; Thu, 4 Aug 2016 14:45:31 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1470311131; bh=bN6iMPfC+TdE+muCN2XTO/SMzpPW5zoJdua5Wjd0YjY=; h=From:To:Subject:Date; b=Fw3sCWhvQHi6dCb8Jqn8/x0QByMNJfZEag2MJRYIABel5R4+VJaqbCnGwYtvG5dMn RWQFm8Lky2ya5VldKbbXi2gvOgcqR2qfHSeYFrC83+wS4pzzYWE72ssLPHnlfHFQSu uf6T4wjJqb3soTe6f4JZhRJBYqT8uLOs+5fwFGCM= From: Dmitry Ivanov To: pgsql-hackers@postgresql.org Subject: Bug in WaitForBackgroundWorkerShutdown() [REL9_5_STABLE] Date: Thu, 04 Aug 2016 14:44:08 +0300 Message-ID: <1637882.WfYN5gPf1A@abook> Organization: Postgres Professional User-Agent: KMail/5.2.3 (Linux/4.6.4-1-ARCH; KDE/5.24.0; x86_64; ; ) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart163398879.1xLPOaUdEz" 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. --nextPart163398879.1xLPOaUdEz 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. -- Dmitry Ivanov Postgres Professional: http://www.postgrespro.com Russian Postgres Company --nextPart163398879.1xLPOaUdEz Content-Disposition: attachment; filename="fix_WaitForBackgroundWorkerShutdown_v1.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="fix_WaitForBackgroundWorkerShutdown_v1.patch" diff --git a/src/backend/postmaster/bgworker.c b/src/backend/postmaster/bgworker.c index 76619e9..5ecb55a 100644 --- a/src/backend/postmaster/bgworker.c +++ b/src/backend/postmaster/bgworker.c @@ -1025,13 +1025,14 @@ 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); } --nextPart163398879.1xLPOaUdEz 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 --nextPart163398879.1xLPOaUdEz--