pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Thomas Munro <thomas.munro@enterprisedb.com>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Andres Freund <andres@anarazel.de>
Cc: Pg Hackers <pgsql-hackers@postgresql.org>
Subject: Re: Condition variable live lock
Date: Mon, 08 Jan 2018 19:02:23 -0500
Message-ID: <20412.1515456143@sss.pgh.pa.us> (raw)
In-Reply-To: <CAEepm=2LqHzizbe7muD7-2yHUbTOoF7Q+qkSD5Q41kuhttRTwA@mail.gmail.com>
References: <CAEepm=0NWKehYw7NDoUSf8juuKOPRnCyY3vuaSvhrEWsOTAa3w@mail.gmail.com>
	<CAEepm=1_S2Ly3Q53yViq29RVJmvaUw8hXs5_ekg_E1uHrNtXGQ@mail.gmail.com>
	<20171229193843.tsbob2xsjfmxkq2g@alap3.anarazel.de>
	<CA+TgmoZykfhWOQWqFcCHL2a-=QVigssd0og1x2AU6jtJsLN-iw@mail.gmail.com>
	<20180104205447.mdaub47aunp3h3mq@alap3.anarazel.de>
	<17054.1515126429@sss.pgh.pa.us>
	<CAEepm=10Es09VfW656CXMnN0LENrAD4Z1Pn8Uxb9rpmDp+0i3Q@mail.gmail.com>
	<21761.1515132657@sss.pgh.pa.us>
	<CAEepm=0zg2dSqHdMbf6ATB9Q4MPCBQfuH23z_00bWEV3wbX-rw@mail.gmail.com>
	<23234.1515134575@sss.pgh.pa.us>
	<CAEepm=2xt_M0PquwBKC6SPm0gpmCUajGsiQ7PLTBAbSuo4O34g@mail.gmail.com>
	<15204.1515166090@sss.pgh.pa.us>
	<14191.1515173593@sss.pgh.pa.us>
	<9342.1515181117@sss.pgh.pa.us>
	<CA+TgmoZS8wr0R4BYD7CfM4CKEbyhi4XmkcORqsLL1CmJMyxOXg@mail.gmail.com>
	<10713.1515182599@sss.pgh.pa.us>
	<26266.1515272424@sss.pgh.pa.us>
	<28942.1515275038@sss.pgh.pa.us>
	<2437.1515368316@sss.pgh.pa.us>
	<CAEepm=3MAW-LVDPmF+6nAUewC3_8mD3gcUPi-VrdBWnCQh7Qrw@mail.gmai! l.com>
	<31228.1515378851@sss.pgh.pa.us>
	<CAEepm=2LqHzizbe7muD7-2yHUbTOoF7Q+qkSD5Q41kuhttRTwA@mail.gmail.com>

Thomas Munro <thomas.munro@enterprisedb.com> writes:
> On Sun, Jan 7, 2018 at 10:00 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Another loose end that I'm seeing here is that while a process waiting on
>> a condition variable will respond to a cancel or die interrupt, it will
>> not notice postmaster death.  This seems unwise to me.  I think we should
>> adjust the WaitLatch call to include WL_POSTMASTER_DEATH as a wake
>> condition and just do a summary proc_exit(1) if it sees that.  I'd even
>> argue that that is a back-patchable bug fix.

> Yeah.  As far as I know so far, every place where we wait on a
> WaitEventSet falls into one of 4 categories when it comes to
> postmaster death:

> 1.  We proc_exit(1) if WL_POSTMASTER_DEATH is returned.
> 2.  We ereport(FATAL) if WL_POSTMASTER_DEATH is returned.
> 3.  We asked for WL_POSTMASTER_DEATH in the WaitEventSet, but we don't
> actually bother checking for it in the returned value.  Instead we
> call PostmasterIsAlive() every time through the loop (pgarch.c,
> syncrep.c, walsender.c and walreceiver.c).
> 4.  We didn't ask for WL_POSTMASTER_DEATH.

> Do I have that right?  I guess category 3 is suboptimal especially on
> some clunky but loveable kernels[1] and all cases of 4 including this
> one are probably bugs.  That makes me wonder why we don't change the
> WaitEventSet API so that it calls proc_exit(1) for you by default if
> you didn't ask to receive WL_POSTMASTER_DEATH explicitly, to handle
> category 1 for free.  If you asked for WL_POSTMASTER_DEATH explicitly
> then we could return it, to support category 2 callers that want to do
> something different.  Just a thought.

Yeah, that's worth thinking about, because I'm pretty sure that we have
had this type of bug before.  We have to be a bit careful because
Andres is thinking of using the WaitEventState support in the postmaster
loop, where it definitely shouldn't check WL_POSTMASTER_DEATH, and it
is probably also possible to reach some of those calls in standalone
backends, which shouldn't either.  So I'm imagining:

1. The WaitEventSet code always includes WL_POSTMASTER_DEATH checking
if IsUnderPostmaster --- and conversely, if !IsUnderPostmaster, it should
ignore any caller request for that.

2. If caller specifies WL_POSTMASTER_DEATH then we'll return that
flag bit, otherwise just exit(1) --- or should the default be
ereport(FATAL)?

3. Remove explicit specification of WL_POSTMASTER_DEATH anywhere that
the default handling is OK, which is probably almost everywhere.
Get rid of those now-redundant PostmasterIsAlive checks, too.

I'm not real sure BTW why we have some callers that ereport and some
that just exit(1).  Seems like it would be better to be consistent,
though I'm not entirely sure which behavior to standardize on.

(Of course, this would only be an appropriate thing to do in HEAD.
In v10 I think we should do the narrow fix I suggested up top.)

			regards, tom lane




view thread (31+ messages)  latest in thread

Message-ID: <20412.1515456143@sss.pgh.pa.us>
Permalink:  ../20412.1515456143@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/20412.1515456143@sss.pgh.pa.us

 · 

reply

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: tgl@sss.pgh.pa.us, thomas.munro@enterprisedb.com, robertmhaas@gmail.com, andres@anarazel.de
  Subject: Re: Condition variable live lock
  In-Reply-To: <20412.1515456143@sss.pgh.pa.us>
  References: <CAEepm=0NWKehYw7NDoUSf8juuKOPRnCyY3vuaSvhrEWsOTAa3w@mail.gmail.com> <20171229193843.tsbob2xsjfmxkq2g@alap3.anarazel.de> <CA+TgmoZykfhWOQWqFcCHL2a-=QVigssd0og1x2AU6jtJsLN-iw@mail.gmail.com> <20180104205447.mdaub47aunp3h3mq@alap3.anarazel.de> <17054.1515126429@sss.pgh.pa.us> <CAEepm=10Es09VfW656CXMnN0LENrAD4Z1Pn8Uxb9rpmDp+0i3Q@mail.gmail.com> <21761.1515132657@sss.pgh.pa.us> <CAEepm=0zg2dSqHdMbf6ATB9Q4MPCBQfuH23z_00bWEV3wbX-rw@mail.gmail.com> <23234.1515134575@sss.pgh.pa.us> <CAEepm=2xt_M0PquwBKC6SPm0gpmCUajGsiQ7PLTBAbSuo4O34g@mail.gmail.com> <15204.1515166090@sss.pgh.pa.us> <14191.1515173593@sss.pgh.pa.us> <9342.1515181117@sss.pgh.pa.us> <CA+TgmoZS8wr0R4BYD7CfM4CKEbyhi4XmkcORqsLL1CmJMyxOXg@mail.gmail.com> <10713.1515182599@sss.pgh.pa.us> <26266.1515272424@sss.pgh.pa.us> <28942.1515275038@sss.pgh.pa.us> <2437.1515368316@sss.pgh.pa.us> <31228.1515378851@sss.pgh.pa.us> <CAEepm=2LqHzizbe7muD7-2yHUbTOoF7Q+qkSD5Q41kuhttRTwA@mail.gmail.com> <20412.1515456143@sss.pgh.pa.us>

* 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