postgresql/src/backend
Thomas Munro 8d578b9b2e Fix race in parallel hash join batch cleanup, take II.
With unlucky timing and parallel_leader_participation=off (not the
default), PHJ could attempt to access per-batch shared state just as it
was being freed.  There was code intended to prevent that by checking
for a cleared pointer, but it was racy.  Fix, by introducing an extra
barrier phase.  The new phase PHJ_BUILD_RUNNING means that it's safe to
access the per-batch state to find a batch to help with, and
PHJ_BUILD_DONE means that it is too late.  The last to detach will free
the array of per-batch state as before, but now it will also atomically
advance the phase, so that late attachers can avoid the hazard.  This
mirrors the way per-batch hash tables are freed (see phases
PHJ_BATCH_PROBING and PHJ_BATCH_DONE).

An earlier attempt to fix this (commit 3b8981b6, later reverted) missed
one special case.  When the inner side is empty (the "empty inner
optimization), the build barrier would only make it to
PHJ_BUILD_HASHING_INNER phase before workers attempted to detach from
the hashtable.  In that case, fast-forward the build barrier to
PHJ_BUILD_RUNNING before proceeding, so that our later assertions hold
and we can still negotiate who is cleaning up.

Revealed by build farm failures, where BarrierAttach() failed a sanity
check assertion, because the memory had been clobbered by dsa_free().
In non-assert builds, the result could be a segmentation fault.

Back-patch to all supported releases.

Author: Thomas Munro <thomas.munro@gmail.com>
Author: Melanie Plageman <melanieplageman@gmail.com>
Reported-by: Michael Paquier <michael@paquier.xyz>
Reported-by: David Geier <geidav.pg@gmail.com>
Tested-by: David Geier <geidav.pg@gmail.com>
Discussion: https://postgr.es/m/20200929061142.GA29096%40paquier.xyz
2023-03-21 14:29:34 +13:00
..
access Ignore BRIN indexes when checking for HOT updates 2023-03-20 11:02:42 +01:00
archive Redesign archive modules 2023-02-17 14:26:42 +09:00
backup Improve several permission-related error messages. 2023-03-17 10:33:09 +01:00
bootstrap Update copyright for 2023 2023-01-02 15:00:37 -05:00
catalog Ignore BRIN indexes when checking for HOT updates 2023-03-20 11:02:42 +01:00
commands Add @extschema:name@ and no_relocate options to extensions. 2023-03-20 18:37:11 -04:00
executor Fix race in parallel hash join batch cleanup, take II. 2023-03-21 14:29:34 +13:00
foreign Update copyright for 2023 2023-01-02 15:00:37 -05:00
jit Fix incorrect format placeholders 2023-03-10 07:10:43 +01:00
lib Fix ILIST_DEBUG build 2023-01-18 10:26:15 -08:00
libpq Add a hook for modifying the ldapbind password 2023-03-15 16:37:28 -04:00
main Mark options as deprecated in usage output 2023-03-02 14:36:37 +01:00
nodes Ignore BRIN indexes when checking for HOT updates 2023-03-20 11:02:42 +01:00
optimizer Have the planner account for the Memoize cache key memory 2023-03-20 16:26:04 +13:00
parser Support [NO] INDENT option in XMLSERIALIZE(). 2023-03-15 16:59:09 -04:00
partitioning Remove useless casts to (void *) in arguments of some system functions 2023-02-07 06:57:59 +01:00
po Update copyright for 2023 2023-01-02 15:00:37 -05:00
port Update copyright for 2023 2023-01-02 15:00:37 -05:00
postmaster Small tidyup for commit d41a178b, part II. 2023-03-17 14:44:12 +13:00
regex Refactor to introduce pg_locale_deterministic(). 2023-02-23 11:17:41 -08:00
replication Improve several permission-related error messages. 2023-03-17 10:33:09 +01:00
rewrite Fix more bugs caused by adding columns to the end of a view. 2023-03-07 18:21:53 -05:00
snowball Update copyright for 2023 2023-01-02 15:00:37 -05:00
statistics Remove unnecessary code in dependency_is_compatible_expression(). 2023-03-14 11:10:45 -04:00
storage Improve several permission-related error messages. 2023-03-17 10:33:09 +01:00
tcop Improve several permission-related error messages. 2023-03-17 10:33:09 +01:00
tsearch Fix t_isspace(), etc., when datlocprovider=i and datctype=C. 2023-03-17 12:08:46 -07:00
utils Ignore BRIN indexes when checking for HOT updates 2023-03-20 11:02:42 +01:00
.gitignore
Makefile Redesign archive modules 2023-02-17 14:26:42 +09:00
common.mk Blind attempt to fix LLVM dependency in the backend 2022-09-15 10:53:48 +07:00
meson.build meson: Prevent installation of test files during main install 2023-03-03 07:45:52 +01:00
nls.mk NLS: Put list of available languages into LINGUAS files 2022-07-13 08:19:17 +02:00