pgsql: Cope with EINVAL and EIDRM shmat() failures inPGSharedMemoryAtt

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Cope with EINVAL and EIDRM shmat() failures inPGSharedMemoryAtt
Дата
Msg-id E1hPAhc-0002oF-Ko@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Cope with EINVAL and EIDRM shmat() failures in PGSharedMemoryAttach.

There's a very old race condition in our code to see whether a pre-existing
shared memory segment is still in use by a conflicting postmaster: it's
possible for the other postmaster to remove the segment in between our
shmctl() and shmat() calls.  It's a narrow window, and there's no risk
unless both postmasters are using the same port number, but that's possible
during parallelized "make check" tests.  (Note that while the TAP tests
take some pains to choose a randomized port number, pg_regress doesn't.)
If it does happen, we treated that as an unexpected case and errored out.

To fix, allow EINVAL to be treated as segment-not-present, and the same
for EIDRM on Linux.  AFAICS, the considerations here are basically
identical to the checks for acceptable shmctl() failures, so I documented
and coded it that way.

While at it, adjust PGSharedMemoryAttach's API to remove its undocumented
dependency on UsedShmemSegAddr in favor of passing the attach address
explicitly.  This makes it easier to be sure we're using a null shmaddr
when probing for segment conflicts (thus avoiding questions about what
EINVAL means).  I don't think there was a bug there, but it required
fragile assumptions about the state of UsedShmemSegAddr during
PGSharedMemoryIsInUse.

Commit c09850992 may have made this failure more probable by applying
the conflicting-segment tests more often.  Hence, back-patch to all
supported branches, as that was.

Discussion: https://postgr.es/m/22224.1557340366@sss.pgh.pa.us

Branch
------
REL9_5_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/91a05390c33c74c8a6bbc7f89d77fe3a8ac5098f

Modified Files
--------------
src/backend/port/sysv_shmem.c | 70 +++++++++++++++++++++++++++++--------------
1 file changed, 47 insertions(+), 23 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Peter Geoghegan
Дата:
Сообщение: Re: pgsql: docs: fist draft version of the PG 12 release notes
Следующее
От: Andres Freund
Дата:
Сообщение: pgsql: Remove reindex_catalog test from test schedules.