Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit59892b1

Browse files
committed
On Windows, retry process creation if we fail to reserve shared memory.
We've heard occasional reports of backend launch failing becausepgwin32_ReserveSharedMemoryRegion() fails, indicating that somethinghas already used that address space in the child process. It's notvery clear what, given that we disable ASLR in Windows builds, butsuspicion falls on antivirus products. It'd be better if we didn'thave to disable ASLR, anyway. So let's try to ameliorate the problemby retrying the process launch after such a failure, up to 100 times.Patch by me, based on previous work by Amit Kapila and others.This is a longstanding issue, so back-patch to all supported branches.Discussion:https://postgr.es/m/CAA4eK1+R6hSx6t_yvwtx+NRzneVp+MRqXAdGJZChcau8Uij-8g@mail.gmail.com
1 parent1b2e875 commit59892b1

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

‎src/backend/postmaster/postmaster.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4347,6 +4347,7 @@ internal_forkexec(int argc, char *argv[], Port *port)
43474347
staticpid_t
43484348
internal_forkexec(intargc,char*argv[],Port*port)
43494349
{
4350+
intretry_count=0;
43504351
STARTUPINFOsi;
43514352
PROCESS_INFORMATIONpi;
43524353
inti;
@@ -4364,6 +4365,9 @@ internal_forkexec(int argc, char *argv[], Port *port)
43644365
Assert(strncmp(argv[1],"--fork",6)==0);
43654366
Assert(argv[2]==NULL);
43664367

4368+
/* Resume here if we need to retry */
4369+
retry:
4370+
43674371
/* Set up shared memory for parameter passing */
43684372
ZeroMemory(&sa,sizeof(sa));
43694373
sa.nLength=sizeof(sa);
@@ -4455,22 +4459,26 @@ internal_forkexec(int argc, char *argv[], Port *port)
44554459

44564460
/*
44574461
* Reserve the memory region used by our main shared memory segment before
4458-
* we resume the child process.
4462+
* we resume the child process. Normally this should succeed, but if ASLR
4463+
* is active then it might sometimes fail due to the stack or heap having
4464+
* gotten mapped into that range. In that case, just terminate the
4465+
* process and retry.
44594466
*/
44604467
if (!pgwin32_ReserveSharedMemoryRegion(pi.hProcess))
44614468
{
4462-
/*
4463-
* Failed to reserve the memory, so terminate the newly created
4464-
* process and give up.
4465-
*/
4469+
/* pgwin32_ReserveSharedMemoryRegion already made a log entry */
44664470
if (!TerminateProcess(pi.hProcess,255))
44674471
ereport(LOG,
44684472
(errmsg_internal("could not terminate process that failed to reserve memory: error code %lu",
44694473
GetLastError())));
44704474
CloseHandle(pi.hProcess);
44714475
CloseHandle(pi.hThread);
4472-
return-1;/* logging done made by
4473-
* pgwin32_ReserveSharedMemoryRegion() */
4476+
if (++retry_count<100)
4477+
gotoretry;
4478+
ereport(LOG,
4479+
(errmsg("giving up after too many tries to reserve shared memory"),
4480+
errhint("This might be caused by ASLR or antivirus software.")));
4481+
return-1;
44744482
}
44754483

44764484
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp