postgresql/src/backend
Tom Lane 81069a9efc Use pselect(2) not select(2), if available, to wait in postmaster's loop.
Traditionally we've unblocked signals, called select(2), and then blocked
signals again.  The code expects that the select() will be cancelled with
EINTR if an interrupt occurs; but there's a race condition, which is that
an already-pending signal will be delivered as soon as we unblock, and then
when we reach select() there will be nothing preventing it from waiting.
This can result in a long delay before we perform any action that
ServerLoop was supposed to have taken in response to the signal.  As with
the somewhat-similar symptoms fixed by commit 893902085, the main practical
problem is slow launching of parallel workers.  The window for trouble is
usually pretty short, corresponding to one iteration of ServerLoop; but
it's not negligible.

To fix, use pselect(2) in place of select(2) where available, as that's
designed to solve exactly this problem.  Where not available, we continue
to use the old way, and are no worse off than before.

pselect(2) has been required by POSIX since about 2001, so most modern
platforms should have it.  A bigger portability issue is that some
implementations are said to be non-atomic, ie pselect() isn't really
any different from unblock/select/reblock.  Still, we're no worse off
than before on such a platform.

There is talk of rewriting the postmaster to use a WaitEventSet and
not do signal response work in signal handlers, at which point this
could be reverted, since we'd be using a self-pipe to solve the race
condition.  But that's not happening before v11 at the earliest.

Back-patch to 9.6.  The problem exists much further back, but the
worst symptom arises only in connection with parallel query, so it
does not seem worth taking any portability risks in older branches.

Discussion: https://postgr.es/m/9205.1492833041@sss.pgh.pa.us
2017-04-24 14:03:14 -04:00
..
access Workaround for RecoverPreparedTransactions() 2017-04-23 22:12:01 +01:00
bootstrap Use one transaction while reading postgres.bki, not one per line. 2017-04-14 17:51:25 -04:00
catalog Modify message when partitioned table is added to publication 2017-04-20 14:18:33 -04:00
commands Code review for commands/statscmds.c. 2017-04-24 11:15:15 -04:00
executor Provide an error cursor for "can't call an SRF here" errors. 2017-04-18 13:21:08 -04:00
foreign Abstract logic to allow for multiple kinds of child rels. 2017-04-03 22:41:31 -04:00
lib Support hashed aggregation with grouping sets. 2017-03-27 04:20:54 +01:00
libpq Change the on-disk format of SCRAM verifiers to conform to RFC 5803. 2017-04-21 22:51:57 +03:00
main Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
nodes Mark finished Plan nodes with parallel_safe flags. 2017-04-12 15:13:34 -04:00
optimizer Fix testing of parallel-safety of SubPlans. 2017-04-18 15:43:56 -04:00
parser Sync addRangeTableEntryForENR() with its peer functions. 2017-04-16 14:02:47 -04:00
po Translation updates 2016-08-08 11:08:00 -04:00
port Provide a way to control SysV shmem attach address in EXEC_BACKEND builds. 2017-04-15 17:27:38 -04:00
postmaster Use pselect(2) not select(2), if available, to wait in postmaster's loop. 2017-04-24 14:03:14 -04:00
regex Fix regexport.c to behave sanely with lookaround constraints. 2017-04-13 17:18:35 -04:00
replication Zero padding in replication origin's checkpointed on disk-state. 2017-04-23 15:54:41 -07:00
rewrite Code review for c94e6942ce. 2017-04-12 11:35:11 -04:00
snowball Add ICU_FLAGS to one more place 2017-03-23 16:53:10 -04:00
statistics Rename columns in new pg_statistic_ext catalog 2017-04-17 18:34:29 -03:00
storage Don't include sys/poll.h anymore. 2017-04-23 16:11:35 -07:00
tcop Improve castNode notation by introducing list-extraction-specific variants. 2017-04-10 13:51:53 -04:00
tsearch Full Text Search support for json and jsonb 2017-03-31 14:26:03 -04:00
utils Also fix comment in sample postgresql.conf file, for "scram-sha-256". 2017-04-18 17:38:32 +03:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
Makefile Implement multivariate n-distinct coefficients 2017-03-24 14:06:10 -03:00
common.mk ICU support 2017-03-23 15:28:48 -04:00
nls.mk Remove trailing slashes from directories in find command 2015-09-18 22:06:54 -04:00