@@ -228,9 +228,10 @@ static php_cgi_globals_struct php_cgi_globals;
228
228
#ifdef PHP_WIN32
229
229
#define WIN32_MAX_SPAWN_CHILDREN 64
230
230
HANDLE kid_cgi_ps [WIN32_MAX_SPAWN_CHILDREN ];
231
- int kids ;
231
+ int kids , cleaning_up = 0 ;
232
232
HANDLE job = NULL ;
233
233
JOBOBJECT_EXTENDED_LIMIT_INFORMATION job_info = { 0 };
234
+ CRITICAL_SECTION cleanup_lock ;
234
235
#endif
235
236
236
237
#ifndef HAVE_ATTRIBUTE_WEAK
@@ -1493,6 +1494,10 @@ BOOL WINAPI fastcgi_cleanup(DWORD sig)
1493
1494
{
1494
1495
int i = kids ;
1495
1496
1497
+ EnterCriticalSection (& cleanup_lock );
1498
+ cleaning_up = 1 ;
1499
+ LeaveCriticalSection (& cleanup_lock );
1500
+
1496
1501
while (0 < i -- ) {
1497
1502
if (NULL == kid_cgi_ps [i ]) {
1498
1503
continue ;
@@ -2129,8 +2134,9 @@ consult the installation file that came with this distribution, or visit \n\
2129
2134
int i ;
2130
2135
2131
2136
ZeroMemory (& kid_cgi_ps , sizeof (kid_cgi_ps ));
2132
- kids = children < WIN32_MAX_SPAWN_CHILDREN ? children : WIN32_MAX_SPAWN_CHILDREN ;
2133
-
2137
+ kids = children < WIN32_MAX_SPAWN_CHILDREN ? children : WIN32_MAX_SPAWN_CHILDREN ;
2138
+
2139
+ InitializeCriticalSection (& cleanup_lock );
2134
2140
SetConsoleCtrlHandler (fastcgi_cleanup , TRUE);
2135
2141
2136
2142
/* kids will inherit the env, don't let them spawn */
@@ -2179,6 +2185,13 @@ consult the installation file that came with this distribution, or visit \n\
2179
2185
}
2180
2186
2181
2187
while (parent ) {
2188
+ EnterCriticalSection (& cleanup_lock );
2189
+ if (cleaning_up ) {
2190
+ DeleteCriticalSection (& cleanup_lock );
2191
+ goto parent_out ;
2192
+ }
2193
+ LeaveCriticalSection (& cleanup_lock );
2194
+
2182
2195
i = kids ;
2183
2196
while (0 < i -- ) {
2184
2197
DWORD status ;
@@ -2234,6 +2247,8 @@ consult the installation file that came with this distribution, or visit \n\
2234
2247
/* restore my env */
2235
2248
SetEnvironmentVariable ("PHP_FCGI_CHILDREN" , kid_buf );
2236
2249
2250
+ DeleteCriticalSection (& cleanup_lock );
2251
+
2237
2252
goto parent_out ;
2238
2253
} else {
2239
2254
parent = 0 ;
0 commit comments