Skip to content

Commit 466c129

Browse files
committed
Fix for postmaster.c function win32_waitpid(int *exitstatus) call to
Win32 WaitForMultipleObjects: ret = WaitForMultipleObjects(win32_numChildren, win32_childHNDArray, FALSE, 0); Problem is 'win32_numChildren' could be more then 64 ( function supports ), problem basically arise ( kills postgres ) when you create more then 64 connections and terminate some of them sill leaving more then 64. Claudio Natoli
1 parent 71fce6c commit 466c129

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/backend/postmaster/postmaster.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.421 2004/08/08 20:17:34 tgl Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.422 2004/08/29 03:16:30 momjian Exp $
4141
*
4242
* NOTES
4343
*
@@ -3736,40 +3736,40 @@ win32_RemoveChild(pid_t pid)
37363736
static pid_t
37373737
win32_waitpid(int *exitstatus)
37383738
{
3739-
Assert(win32_childPIDArray && win32_childHNDArray);
3740-
elog(DEBUG3, "waiting on %lu children", win32_numChildren);
3741-
3742-
if (win32_numChildren > 0)
3743-
{
37443739
/*
37453740
* Note: Do NOT use WaitForMultipleObjectsEx, as we don't want to
37463741
* run queued APCs here.
37473742
*/
37483743
int index;
37493744
DWORD exitCode;
37503745
DWORD ret;
3746+
unsigned long offset;
37513747

3752-
ret = WaitForMultipleObjects(win32_numChildren, win32_childHNDArray,
3753-
FALSE, 0);
3748+
Assert(win32_childPIDArray && win32_childHNDArray);
3749+
elog(DEBUG3, "waiting on %lu children", win32_numChildren);
3750+
3751+
for (offset = 0; offset < win32_numChildren; offset += MAXIMUM_WAIT_OBJECTS)
3752+
{
3753+
unsigned long num = min(MAXIMUM_WAIT_OBJECTS, win32_numChildren - offset);
3754+
ret = WaitForMultipleObjects(num, &win32_childHNDArray[offset], FALSE, 0);
37543755
switch (ret)
37553756
{
37563757
case WAIT_FAILED:
37573758
ereport(LOG,
3758-
(errmsg_internal("failed to wait on %lu children: %d",
3759-
win32_numChildren, (int) GetLastError())));
3759+
(errmsg_internal("failed to wait on %lu of %lu children: %d",
3760+
num, win32_numChildren, (int) GetLastError())));
37603761
return -1;
37613762

37623763
case WAIT_TIMEOUT:
3763-
/* No children have finished */
3764-
return -1;
3764+
/* No children (in this chunk) have finished */
3765+
break;
37653766

37663767
default:
3767-
37683768
/*
37693769
* Get the exit code, and return the PID of, the
37703770
* respective process
37713771
*/
3772-
index = ret - WAIT_OBJECT_0;
3772+
index = offset + ret - WAIT_OBJECT_0;
37733773
Assert(index >= 0 && index < win32_numChildren);
37743774
if (!GetExitCodeProcess(win32_childHNDArray[index], &exitCode))
37753775
{
@@ -3787,7 +3787,7 @@ win32_waitpid(int *exitstatus)
37873787
}
37883788
}
37893789

3790-
/* No children */
3790+
/* No children have finished */
37913791
return -1;
37923792
}
37933793

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