pgsql: Server-side fix for delayed NOTIFY and SIGTERM processing. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Server-side fix for delayed NOTIFY and SIGTERM processing.
Date
Msg-id E1gDgv5-0005Xc-7L@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Server-side fix for delayed NOTIFY and SIGTERM processing.

Commit 4f85fde8e introduced some code that was meant to ensure that we'd
process cancel, die, sinval catchup, and notify interrupts while waiting
for client input.  But there was a flaw: it supposed that the process
latch would be set upon arrival at secure_read() if any such interrupt
was pending.  In reality, we might well have cleared the process latch
at some earlier point while those flags remained set -- particularly
notifyInterruptPending, which can't be handled as long as we're within
a transaction.

To fix the NOTIFY case, also attempt to process signals (except
ProcDiePending) before trying to read.

Also, if we see that ProcDiePending is set before we read, forcibly set the
process latch to ensure that we will handle that signal promptly if no data
is available.  I also made it set the process latch on the way out, in case
there is similar logic elsewhere.  (It remains true that we won't service
ProcDiePending here unless we need to wait for input.)

The code for handling ProcDiePending during a write needs those changes,
too.

Also be a little more careful about when to reset whereToSendOutput,
and improve related comments.

Back-patch to 9.5 where this code was added.  I'm not entirely convinced
that older branches don't have similar issues, but the complaint at hand
is just about the >= 9.5 code.

Jeff Janes and Tom Lane

Discussion: https://postgr.es/m/CAOYf6ec-TmRYjKBXLLaGaB-jrd=mjG1Hzn1a1wufUAR39PQYhw@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/2ddb9149d14de9a2e7ac9ec6accf3ad442702b24

Modified Files
--------------
src/backend/libpq/be-secure.c | 20 ++++++-----
src/backend/tcop/postgres.c   | 77 ++++++++++++++++++++++++++++---------------
2 files changed, 62 insertions(+), 35 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Sync our copy of the timezone library with IANA releasetzcode20
Next
From: Michael Paquier
Date:
Subject: Re: pgsql: Silence perlcritic warning about missing return.