@@ -230,9 +230,10 @@ static php_cgi_globals_struct php_cgi_globals;
230
230
#ifdef PHP_WIN32
231
231
#define WIN32_MAX_SPAWN_CHILDREN 64
232
232
HANDLE kid_cgi_ps [WIN32_MAX_SPAWN_CHILDREN ];
233
- int kids ;
233
+ int kids , cleaning_up = 0 ;
234
234
HANDLE job = NULL ;
235
235
JOBOBJECT_EXTENDED_LIMIT_INFORMATION job_info = { 0 };
236
+ CRITICAL_SECTION cleanup_lock ;
236
237
#endif
237
238
238
239
#ifndef HAVE_ATTRIBUTE_WEAK
@@ -1496,6 +1497,10 @@ BOOL WINAPI fastcgi_cleanup(DWORD sig)
1496
1497
{
1497
1498
int i = kids ;
1498
1499
1500
+ EnterCriticalSection (& cleanup_lock );
1501
+ cleaning_up = 1 ;
1502
+ LeaveCriticalSection (& cleanup_lock );
1503
+
1499
1504
while (0 < i -- ) {
1500
1505
if (NULL == kid_cgi_ps [i ]) {
1501
1506
continue ;
@@ -2180,6 +2185,7 @@ consult the installation file that came with this distribution, or visit \n\
2180
2185
ZeroMemory (& kid_cgi_ps , sizeof (kid_cgi_ps ));
2181
2186
kids = children < WIN32_MAX_SPAWN_CHILDREN ? children : WIN32_MAX_SPAWN_CHILDREN ;
2182
2187
2188
+ InitializeCriticalSection (& cleanup_lock );
2183
2189
SetConsoleCtrlHandler (fastcgi_cleanup , TRUE);
2184
2190
2185
2191
/* kids will inherit the env, don't let them spawn */
@@ -2228,6 +2234,13 @@ consult the installation file that came with this distribution, or visit \n\
2228
2234
}
2229
2235
2230
2236
while (parent ) {
2237
+ EnterCriticalSection (& cleanup_lock );
2238
+ if (cleaning_up ) {
2239
+ DeleteCriticalSection (& cleanup_lock );
2240
+ goto parent_out ;
2241
+ }
2242
+ LeaveCriticalSection (& cleanup_lock );
2243
+
2231
2244
i = kids ;
2232
2245
while (0 < i -- ) {
2233
2246
DWORD status ;
@@ -2283,6 +2296,8 @@ consult the installation file that came with this distribution, or visit \n\
2283
2296
/* restore my env */
2284
2297
SetEnvironmentVariable ("PHP_FCGI_CHILDREN" , kid_buf );
2285
2298
2299
+ DeleteCriticalSection (& cleanup_lock );
2300
+
2286
2301
goto parent_out ;
2287
2302
} else {
2288
2303
parent = 0 ;
0 commit comments