postgresql/src/include
Thomas Munro 0129c56fbe Fix race in Parallel Hash Join batch cleanup.
With very unlucky timing and parallel_leader_participation off, PHJ
could attempt to access per-batch state just as it was being freed.
There was code intended to prevent that by checking for a cleared
pointer, but it was buggy.

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 at the same time, so that
late attachers can avoid the hazard, without the data race.  This
mirrors the way per-batch hash tables are freed (see phases
PHJ_BATCH_PROBING and PHJ_BATCH_DONE).

Revealed by a one-off build farm failure, where BarrierAttach() failed a
sanity check assertion, because the memory had been clobbered by
dsa_free().

Back-patch to 11, where the code arrived.

Reported-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/20200929061142.GA29096%40paquier.xyz
2021-03-17 18:10:17 +13:00
..
access Fix permission checks on constraint violation errors on partitions. 2021-02-08 11:01:55 +02:00
bootstrap Rationalize handling of array type names in bootstrap data. 2018-04-17 18:29:11 -04:00
catalog Prevent drop of tablespaces used by partitioned relations 2021-01-14 15:32:14 -03:00
commands Move CloneForeignKeyConstraints to tablecmds.c 2019-01-18 14:57:49 -03:00
common Move connect.h from fe_utils to src/include/common. 2020-08-10 09:22:59 -07:00
datatype Update copyright for 2018 2018-01-02 23:30:12 -05:00
executor Fix race in Parallel Hash Join batch cleanup. 2021-03-17 18:10:17 +13:00
fe_utils Ensure schema qualification in pg_restore DISABLE/ENABLE TRIGGER commands. 2018-08-17 17:12:21 -04:00
foreign Allow insert and update tuple routing and COPY for foreign tables. 2018-04-06 19:22:03 -04:00
jit llvmjit: Work around bug in LLVM 3.9 causing crashes after 72559438f9. 2020-10-15 18:17:01 -07:00
lib simplehash: Add support for resetting a hashtable's contents. 2019-02-09 01:05:50 -08:00
libpq Fix unportable use of getnameinfo() in pg_hba_file_rules view. 2020-11-02 21:11:50 -05:00
mb Fix a boatload of typos in C comments. 2018-04-01 15:01:28 -04:00
nodes Fix permission checks on constraint violation errors on partitions. 2021-02-08 11:01:55 +02:00
optimizer Be more careful about the shape of hashable subplan clauses. 2020-08-14 22:14:03 -04:00
parser Fix handling of CREATE TABLE LIKE with inheritance. 2020-08-21 15:00:43 -04:00
partitioning Fix hash partition pruning with asymmetric partition sets. 2021-01-28 13:41:55 -05:00
port Default to wal_sync_method=fdatasync on FreeBSD. 2021-02-15 16:06:25 +13:00
portability Update copyright for 2018 2018-01-02 23:30:12 -05:00
postmaster Fix race condition between shutdown and unstarted background workers. 2020-12-24 17:00:43 -05:00
regex Update copyright for 2018 2018-01-02 23:30:12 -05:00
replication Fix bogus cache-invalidation logic in logical replication worker. 2020-09-16 12:07:31 -04:00
rewrite Defend against self-referential views in relation_is_updatable(). 2019-11-21 16:21:44 -05:00
snowball Update copyright for 2018 2018-01-02 23:30:12 -05:00
statistics Update copyright for 2018 2018-01-02 23:30:12 -05:00
storage Fix CREATE INDEX CONCURRENTLY for simultaneous prepared transactions. 2021-01-30 00:02:08 -08:00
tcop Fix event triggers for partitioned tables 2018-10-06 19:17:46 -03:00
tsearch Post-feature-freeze pgindent run. 2018-04-26 14:47:16 -04:00
utils Fix and simplify some usages of TimestampDifference(). 2020-11-10 22:51:56 -05:00
.gitignore Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
c.h pg_attribute_no_sanitize_alignment() macro 2021-02-13 17:49:08 -05:00
fmgr.h Fix minor violations of FunctionCallInvoke usage protocol. 2020-04-21 14:23:59 -04:00
funcapi.h Avoid holding a directory FD open across assorted SRF calls. 2020-03-16 21:05:54 -04:00
getaddrinfo.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
getopt_long.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
Makefile Install JIT related headers. 2019-01-28 13:53:43 -08:00
miscadmin.h Add unlikely() to CHECK_FOR_INTERRUPTS() 2020-06-05 16:49:32 -04:00
pg_config.h.in Replace use of sys_siglist[] with strsignal(). 2020-07-15 22:05:12 -04:00
pg_config.h.win32 Stamp 11.11. 2021-02-08 16:57:36 -05:00
pg_config_ext.h.in Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_ext.h.win32 Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_manual.h Improve description of DEFAULT_XLOG_SEG_SIZE in pg_config.h 2018-12-29 08:24:47 +09:00
pg_getopt.h Use our own getopt() on OpenBSD. 2019-01-18 15:06:26 -05:00
pg_trace.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
pgstat.h Add GUC variables for stat tracking and timeout as PGDLLIMPORT 2020-01-21 13:47:01 +09:00
pgtar.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
pgtime.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
port.h In the postmaster, rely on the signal infrastructure to block signals. 2020-10-15 12:50:57 -04:00
postgres.h Detoast plpgsql variables if they might live across a transaction boundary. 2018-05-16 14:56:52 -04:00
postgres_ext.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
postgres_fe.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
rusagestub.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
windowapi.h Update copyright for 2018 2018-01-02 23:30:12 -05:00