postgresql/src/backend/storage
Masahiko Sawada 1a9b1cc18e Fix race between ProcSignalInit() and EmitProcSignalBarrier().
Previously, ProcSignalInit() read the global barrier generation before
publishing its PID into pss_pid. This created a race condition: a
process could initialize its local generation with an older global
value, while a concurrent EmitProcSignalBarrier() might skip that
process because its pss_pid was still zero. This resulted in
WaitForProcSignalBarrier() hanging indefinitely.

Fix this by publishing pss_pid before reading psh_barrierGeneration
with a memory barrier so that the store to pss_pid is ordered before
the load. A concurrent EmitProcSignalBarrier() then either observes
the published PID and signals this slot, or completes its generation
increment before we load it.

While this race has become more visible due to recent features using
signal barriers in more places (such as online wal_level changes), the
issue is theoretically present since signal barriers were introduced
to release smgr caches (e.g., in DROP DATABASE). v14 has the
procsiangl barrier infrastricutre but no in-tree caller that actually
emits a barrier, so the case is unreachable there.

This issue was also reported by buildfarm member flaviventris.

Reported-by: Melanie Plageman <melanieplageman@gmail.com>
Reviewed-by: Alexander Lakhin <exclusion@gmail.com>
Reviewed-by: Matthias van de Meent <boekewurm+postgres@gmail.com>
Discussion: https://postgr.es/m/CAEze2WgAJmWReDN7Chtba8Er2YBvKCoa0KVN25-1evnTrHsLyA@mail.gmail.com
Backpatch-through: 15
2026-05-27 16:25:59 -07:00
..
aio Prevent access to other sessions' temp tables 2026-05-14 15:06:27 +03:00
buffer Prevent access to other sessions' temp tables 2026-05-14 15:06:27 +03:00
file Fix errno check based on EINTR in pg_flush_data() 2026-04-30 18:44:41 +09:00
freespace Mark modified the FSM buffer as dirty during recovery 2026-05-03 20:27:36 +03:00
ipc Fix race between ProcSignalInit() and EmitProcSignalBarrier(). 2026-05-27 16:25:59 -07:00
large_object Update copyright for 2025 2025-01-01 11:21:55 -05:00
lmgr Fix procLatch ownership race in ProcKill() 2026-05-27 17:19:53 +09:00
page meson: build checksums with extra optimization flags. 2025-09-09 16:04:04 -07:00
smgr Add file_extend_method=posix_fallocate,write_zeros. 2026-02-06 17:38:39 +13:00
sync Update copyright for 2025 2025-01-01 11:21:55 -05:00
Makefile Provide API for streaming relation data. 2024-04-03 00:49:46 +13:00
meson.build Update copyright for 2025 2025-01-01 11:21:55 -05:00