pgsql: On Windows, ensure shared memory handle gets closed if not being - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: On Windows, ensure shared memory handle gets closed if not being
Date
Msg-id E1Zm1Op-0003he-5v@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
On Windows, ensure shared memory handle gets closed if not being used.

Postmaster child processes that aren't supposed to be attached to shared
memory were not bothering to close the shared memory mapping handle they
inherit from the postmaster process.  That's mostly harmless, since the
handle vanishes anyway when the child process exits -- but the syslogger
process, if used, doesn't get killed and restarted during recovery from a
backend crash.  That meant that Windows doesn't see the shared memory
mapping as becoming free, so it doesn't delete it and the postmaster is
unable to create a new one, resulting in failure to recover from crashes
whenever logging_collector is turned on.

Per report from Dmitry Vasilyev.  It's a bit astonishing that we'd not
figured this out long ago, since it's been broken from the very beginnings
of out native Windows support; probably some previously-unexplained trouble
reports trace to this.

A secondary problem is that on Cygwin (perhaps only in older versions?),
exec() may not detach from the shared memory segment after all, in which
case these child processes did remain attached to shared memory, posing
the risk of an unexpected shared memory clobber if they went off the rails
somehow.  That may be a long-gone bug, but we can deal with it now if it's
still live, by detaching within the infrastructure introduced here to deal
with closing the handle.

Back-patch to all supported branches.

Tom Lane and Amit Kapila

Branch
------
REL9_5_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/39ac293940ec022f36510ba72470f23799e21dde

Modified Files
--------------
src/backend/port/sysv_shmem.c       |   53 ++++++++++++++++++----
src/backend/port/win32_shmem.c      |   82 ++++++++++++++++++++++++++++-------
src/backend/postmaster/postmaster.c |    5 ++-
src/include/storage/pg_shmem.h      |    1 +
4 files changed, 116 insertions(+), 25 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: On Windows, ensure shared memory handle gets closed if not being
Next
From: Tom Lane
Date:
Subject: pgsql: On Windows, ensure shared memory handle gets closed if not being