latch usage and postmaster death

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-hackers(at)postgresql(dot)org, Robert Haas <robertmhaas(at)gmail(dot)com>
Subject: latch usage and postmaster death
Date: 2016-03-21 09:35:34
Message-ID: 20160321093534.inkduxvpirs5n44j@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

a significant number of WaitLatch's in the backend currently don't check
for postmaster death. That's imo wrong. E.g. SELECT pg_sleep(100); just
continues to run.

I think we should change most sites to error out in that case. I wonder
if we shouldn't add another WL_ flag that automatically makes the latch
code do so; instead of repeating the code at every callsite.

Places that I've noticed in a quick skim:
* pg_sleep()
* gather_getnext()
* shm_mq_send_bytes()?
* shm_mq_receive_bytes()?
* ProcSleep()?
* ProcWaitForSignal()

The only case where we don't necessarily want to react to postmaster
death is syslogger, which is supposed to finish logging before shutting
down.

Additionally I noticed that we're not always diligent about following
the correct pattern when using latches. For example check
gather_readnext():
/* Nothing to do except wait for developments. */
WaitLatch(MyLatch, WL_LATCH_SET, 0);
CHECK_FOR_INTERRUPTS();
ResetLatch(MyLatch);
we should reset the latch before checking for interrupts, not
after. This way an interrupt that arrives between the two will possibly
be ignored.

Greetings,

Andres Freund

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Grzegorz Sampolski 2016-03-21 09:59:20 Re: pam auth - add rhost item
Previous Message Robert Haas 2016-03-21 09:34:07 Re: multivariate statistics v14