postgresql/src/backend/storage/ipc
Thomas Munro 6c0fb94189 Fix race in dsm_attach() when handles are reused.
DSM handle values can be reused as soon as the underlying shared memory
object has been destroyed.  That means that for a brief moment we
might have two DSM slots with the same handle.  While trying to attach,
if we encounter a slot with refcnt == 1, meaning that it is currently
being destroyed, we should continue our search in case the same handle
exists in another slot.

The race manifested as a rare "dsa_area could not attach to segment"
error, and was more likely in 10 and 11 due to the lack of distinct
seed for random() in parallel workers.  It was made very unlikely in
in master by commit 197e4af9, and older releases don't usually create
new DSM segments in background workers so it was also unlikely there.

This fixes the root cause of bug report #15585, in which the error
could also sometimes result in a self-deadlock in the error path.
It's not yet clear if further changes are needed to avoid that failure
mode.

Back-patch to 9.4, where dsm.c arrived.

Author: Thomas Munro
Reported-by: Justin Pryzby, Sergei Kornilov
Discussion: https://postgr.es/m/20190207014719.GJ29720@telsasoft.com
Discussion: https://postgr.es/m/15585-324ff6a93a18da46@postgresql.org
2019-02-15 14:05:09 +13:00
..
Makefile Refactor user-facing SQL functions signalling backends 2018-10-04 18:27:25 +09:00
barrier.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
dsm.c Fix race in dsm_attach() when handles are reused. 2019-02-15 14:05:09 +13:00
dsm_impl.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
ipc.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
ipci.c Add shared_memory_type GUC. 2019-02-03 12:47:26 +01:00
latch.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
pmsignal.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
procarray.c Move remaining code from tqual.[ch] to heapam.h / heapam_visibility.c. 2019-01-21 17:07:10 -08:00
procsignal.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
shm_mq.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
shm_toc.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
shmem.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
shmqueue.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
signalfuncs.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
sinval.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
sinvaladt.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
standby.c Update copyright for 2019 2019-01-02 12:44:25 -05:00