Get more info about Windows can't-reattach-to-shared-memory errors.

Commit 63ca350ef neglected to probe the state of things *before*
the VirtualFree call, which now looks like it might be interesting.

Discussion: https://postgr.es/m/25495.1524517820@sss.pgh.pa.us
This commit is contained in:
Tom Lane 2018-04-29 16:02:45 -04:00
parent df629586e8
commit 68e7e973d2
1 changed files with 18 additions and 2 deletions

View File

@ -388,10 +388,18 @@ PGSharedMemoryReAttach(void)
{
PGShmemHeader *hdr;
void *origUsedShmemSegAddr = UsedShmemSegAddr;
MEMORY_BASIC_INFORMATION previnfo;
DWORD queryerr;
Assert(UsedShmemSegAddr != NULL);
Assert(IsUnderPostmaster);
/* Preliminary probe of region we intend to release */
if (VirtualQuery(UsedShmemSegAddr, &previnfo, sizeof(previnfo)) != 0)
queryerr = 0;
else
queryerr = GetLastError();
/*
* Release memory region reservation that was made by the postmaster
*/
@ -405,12 +413,20 @@ PGSharedMemoryReAttach(void)
DWORD maperr = GetLastError();
MEMORY_BASIC_INFORMATION info;
if (queryerr == 0)
elog(LOG, "VirtualQuery(%p) before free reports region of size %zu, base %p, has state 0x%lx",
UsedShmemSegAddr, previnfo.RegionSize,
previnfo.AllocationBase, previnfo.State);
else
elog(LOG, "VirtualQuery(%p) before free failed: error code %lu",
UsedShmemSegAddr, queryerr);
if (VirtualQuery(UsedShmemSegAddr, &info, sizeof(info)) != 0)
elog(LOG, "VirtualQuery(%p) reports region of size %zu, base %p, has state 0x%lx",
elog(LOG, "VirtualQuery(%p) after free reports region of size %zu, base %p, has state 0x%lx",
UsedShmemSegAddr, info.RegionSize,
info.AllocationBase, info.State);
else
elog(LOG, "VirtualQuery(%p) failed: error code %lu",
elog(LOG, "VirtualQuery(%p) after free failed: error code %lu",
UsedShmemSegAddr, GetLastError());
elog(FATAL, "could not reattach to shared memory (key=%p, addr=%p): error code %lu",