Skip to content

Commit 68e7e97

Browse files
committed
Get more info about Windows can't-reattach-to-shared-memory errors.
Commit 63ca350 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
1 parent df62958 commit 68e7e97

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/backend/port/win32_shmem.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,18 @@ PGSharedMemoryReAttach(void)
388388
{
389389
PGShmemHeader *hdr;
390390
void *origUsedShmemSegAddr = UsedShmemSegAddr;
391+
MEMORY_BASIC_INFORMATION previnfo;
392+
DWORD queryerr;
391393

392394
Assert(UsedShmemSegAddr != NULL);
393395
Assert(IsUnderPostmaster);
394396

397+
/* Preliminary probe of region we intend to release */
398+
if (VirtualQuery(UsedShmemSegAddr, &previnfo, sizeof(previnfo)) != 0)
399+
queryerr = 0;
400+
else
401+
queryerr = GetLastError();
402+
395403
/*
396404
* Release memory region reservation that was made by the postmaster
397405
*/
@@ -405,12 +413,20 @@ PGSharedMemoryReAttach(void)
405413
DWORD maperr = GetLastError();
406414
MEMORY_BASIC_INFORMATION info;
407415

416+
if (queryerr == 0)
417+
elog(LOG, "VirtualQuery(%p) before free reports region of size %zu, base %p, has state 0x%lx",
418+
UsedShmemSegAddr, previnfo.RegionSize,
419+
previnfo.AllocationBase, previnfo.State);
420+
else
421+
elog(LOG, "VirtualQuery(%p) before free failed: error code %lu",
422+
UsedShmemSegAddr, queryerr);
423+
408424
if (VirtualQuery(UsedShmemSegAddr, &info, sizeof(info)) != 0)
409-
elog(LOG, "VirtualQuery(%p) reports region of size %zu, base %p, has state 0x%lx",
425+
elog(LOG, "VirtualQuery(%p) after free reports region of size %zu, base %p, has state 0x%lx",
410426
UsedShmemSegAddr, info.RegionSize,
411427
info.AllocationBase, info.State);
412428
else
413-
elog(LOG, "VirtualQuery(%p) failed: error code %lu",
429+
elog(LOG, "VirtualQuery(%p) after free failed: error code %lu",
414430
UsedShmemSegAddr, GetLastError());
415431

416432
elog(FATAL, "could not reattach to shared memory (key=%p, addr=%p): error code %lu",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy