php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45423 fastcgi parent process doesn't invoke php_module_shutdown before shutdown
Submitted: 2008-07-03 02:16 UTC Modified: 2008-07-15 13:13 UTC
From: basant dot kukreja at sun dot com Assigned: dmitry (profile)
Status: Closed Package: CGI/CLI related
PHP Version: 5.2.6 OS: *
Private report: No CVE-ID: None
 [2008-07-03 02:16 UTC] basant dot kukreja at sun dot com
Description:
------------
php fastcgi parent process calls sapi_startup but it doesn't call
php_module_shutdown before exiting. The result of this is :
1) php behavior is different when running inside apache and inside fastcgi.
   When running inside apache, parent apache process calls php_module_shutdown.
2) Since php fastcgi parent doesn't call php_module_shutodown, it doesn't give
   modules like apc to do proper cleanup chance. Note that apc creates semaphores
   and it needs to know if parent process is shutting down to cleanup semaphores.
   Here is the APC  bug link : http://pecl.php.net/bugs/bug.php?id=5280




Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-03 02:18 UTC] basant dot kukreja at sun dot com
Suggested fix :
   Php fastcgi parent process install signals and inside signal handler it calls
exit. I think it is not wise to call complicated stuff like php_module_shutdown
inside signal handler so in my suggested fix, I set the variable exitsignal to 1.
When parent will come out of wait call, it should first invoke cleanup functions
and then call exit.

--- sapi/cgi/cgi_main.c_orig	2008-04-09 02:16:40.000000000 -0700
+++ sapi/cgi/cgi_main.c	2008-07-02 18:56:44.968570000 -0700
@@ -103,6 +103,12 @@
  */
 static int parent = 1;
 
+/* Did parent received exit signals SIG_TERM/SIG_INT/SIG_QUIT */
+static int exitsignal = 0;
+
+/* Is Parent waiting for children to exit */
+static int parentwaiting = 0;
+
 /**
  * Process group
  */
@@ -1151,9 +1157,13 @@
 	/* Kill all the processes in our process group */
 	kill(-pgroup, SIGTERM);
 #endif
-
 	/* We should exit at this point, but MacOSX doesn't seem to */
-	exit(0);
+	if (parent && parentwaiting) {
+		exitsignal = 1;
+	}
+	else {
+		exit(0);
+	}
 }
 #endif
 
@@ -1557,8 +1567,15 @@
 #ifdef DEBUG_FASTCGI
 				fprintf(stderr, "Wait for kids, pid %d\n", getpid());
 #endif
+				parentwaiting = 1;
 				while (wait(&status) < 0) {
 				}
+				if (exitsignal) {
+					SG(server_context) = NULL;
+					php_module_shutdown(TSRMLS_C);
+					sapi_shutdown();
+					exit(0);
+				}
 				running--;
 			}
 		}
 [2008-07-15 02:03 UTC] jani@php.net
Dmitry, this patch looks okay to me..can I have a second opinion from you? :)
 [2008-07-15 13:13 UTC] dmitry@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC