postgresql/src/backend/storage/ipc
Thomas Munro 389869af59 Harden dsm_impl.c against unexpected EEXIST.
Previously, we trusted the OS not to report EEXIST unless we'd passed in
IPC_CREAT | IPC_EXCL or O_CREAT | O_EXCL, as appropriate.  Solaris's
shm_open() can in fact do that, causing us to crash because we didn't
ereport and then we blithely assumed the mapping was successful.

Let's treat EEXIST just like any other error, unless we're actually
trying to create a new segment.  This applies to shm_open(), where this
behavior has been seen, and also to the equivalent operations for our
sysv and mmap modes just on principle.

Based on the underlying reason for the error, namely contention on a
lock file managed by Solaris librt for each distinct name, this problem
is only likely to happen on 15 and later, because the new shared memory
stats system produces shm_open() calls for the same path from
potentially large numbers of backends concurrently during
authentication.  Earlier releases only shared memory segments between a
small number of parallel workers under one Gather node.  You could
probably hit it if you tried hard enough though, and we should have been
more defensive in the first place.  Therefore, back-patch to all
supported releases.

Per build farm animal margay.  This isn't the end of the story, though,
it just changes random crashes into random "File exists" errors; more
work needed for a green build farm.

Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Discussion: https://postgr.es/m/CA%2BhUKGKqKrCV5xKWfh9rnm%3Do%3DDwZLTLtnsj_XpUi9g5%3DV%2B9oyg%40mail.gmail.com
2022-07-01 14:17:54 +12:00
..
Makefile Split all OBJS style lines in makefiles into one-line-per-entry style. 2019-11-05 14:41:07 -08:00
barrier.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
dsm.c Revert the addition of GetMaxBackends() and related stuff. 2022-04-12 14:45:23 -04:00
dsm_impl.c Harden dsm_impl.c against unexpected EEXIST. 2022-07-01 14:17:54 +12:00
ipc.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
ipci.c Be more careful about GucSource for internally-driven GUC settings. 2022-06-08 13:26:18 -04:00
latch.c Don't trust signalfd() on illumos. 2022-06-26 10:55:21 +12:00
pmsignal.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
procarray.c Fix visibility check when XID is committed in CLOG but not in procarray. 2022-06-27 08:21:08 +03:00
procsignal.c Add logging for excessive ProcSignalBarrier waits. 2022-05-11 18:03:03 +12:00
shm_mq.c shm_mq_sendv: Fix flushing bug when receiver not yet attached. 2022-05-31 08:46:54 -04:00
shm_toc.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
shmem.c Create routine able to set single-call SRFs for Materialize mode 2022-03-07 10:26:29 +09:00
shmqueue.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
signalfuncs.c Improve warning message in pg_signal_backend() 2022-01-11 12:56:26 -05:00
sinval.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
sinvaladt.c Pre-beta mechanical code beautification. 2022-05-12 15:17:30 -04:00
standby.c Clean up newlines following left parentheses 2022-05-13 23:52:35 +02:00