From: Dmitry Ivanov <d.ivanov@postgrespro.ru>
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> (raw)
In-Reply-To: <1637882.WfYN5gPf1A@abook>
References: <1637882.WfYN5gPf1A@abook>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
> 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
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackersAttachments:fix_WaitForBackgroundWorkerShutdown_v2.patch (text/x-patch, 661B) downloaddiff --git a/src/backend/postmaster/bgworker.c b/src/backend/postmaster/bgworker.cindex 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);
}
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: d.ivanov@postgrespro.ru
Subject: Re: Bug in WaitForBackgroundWorkerShutdown() [REL9_5_STABLE]
In-Reply-To: <1996641.25QjV5kv6m@abook>
References: <1637882.WfYN5gPf1A@abook> <1996641.25QjV5kv6m@abook>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox