postgresql/src/backend
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
..
access Fix code comments still referring to pg_start/stop_backup() 2022-07-01 09:37:17 +09:00
bootstrap Be more careful about GucSource for internally-driven GUC settings. 2022-06-08 13:26:18 -04:00
catalog Fix typo in pg_publication.c 2022-06-23 16:42:27 +09:00
commands CREATE INDEX: use the original userid for more ACL checks. 2022-06-25 09:07:41 -07:00
executor Un-break whole-row Vars referencing domain-over-composite types. 2022-06-10 10:35:57 -04:00
foreign Create routine able to set single-call SRFs for Materialize mode 2022-03-07 10:26:29 +09:00
jit Pre-beta mechanical code beautification. 2022-05-12 15:17:30 -04:00
lib Pre-beta mechanical code beautification. 2022-05-12 15:17:30 -04:00
libpq Remove misguided SSL key file ownership check in libpq. 2022-05-26 14:14:05 -04:00
main Fix collection of typos in the code and the documentation 2022-03-15 11:29:35 +09:00
nodes Harden range_table_mutator() against null RangeTblEntry.subquery. 2022-06-26 08:58:05 -04:00
optimizer Improve comments for trivial_subqueryscan(). 2022-06-09 19:30:00 +09:00
parser Fix collation of JSON_TABLE output columns 2022-06-10 06:05:08 +02:00
partitioning Pre-beta mechanical code beautification. 2022-05-12 15:17:30 -04:00
po Translation updates 2022-06-27 08:19:02 +02:00
port Ensure that the argument of shmdt(2) is declared "void *". 2022-02-15 17:17:28 -05:00
postmaster Be more careful about GucSource for internally-driven GUC settings. 2022-06-08 13:26:18 -04:00
regex Pre-beta mechanical code beautification. 2022-05-12 15:17:30 -04:00
replication Fix code comments still referring to pg_start/stop_backup() 2022-07-01 09:37:17 +09:00
rewrite Fix incautious CTE matching in rewriteSearchAndCycle(). 2022-04-23 12:16:12 -04:00
snowball Update copyright for 2022 2022-01-07 19:04:57 -05:00
statistics Pre-beta mechanical code beautification. 2022-05-12 15:17:30 -04:00
storage Harden dsm_impl.c against unexpected EEXIST. 2022-07-01 14:17:54 +12:00
tcop Fix DDL deparse of CREATE OPERATOR CLASS 2022-05-20 18:52:55 +02:00
tsearch Remove extraneous blank lines before block-closing braces 2022-04-13 19:16:02 +02:00
utils Change some unnecessary MemSet calls 2022-07-01 00:16:38 +02:00
.gitignore
Makefile Server-side gzip compression. 2022-01-24 15:13:18 -05:00
common.mk Remove PARTIAL_LINKING build mode. 2018-03-30 17:33:04 -07:00
nls.mk Report progress of startup operations that take a long time. 2021-10-25 11:51:57 -04:00