You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mod_python-commits@quetz.apache.org by jg...@apache.org on 2005/10/23 04:05:03 UTC

svn commit: r327728 - /httpd/mod_python/trunk/lib/python/mod_python/Session.py

Author: jgallacher
Date: Sat Oct 22 19:05:01 2005
New Revision: 327728

URL: http://svn.apache.org/viewcvs?rev=327728&view=rev
Log:
Fixed possible problem where a stale lockfile will keep the filesession 
cleanup from running.

A lockfile is used to ensure that only one process can run the cleanup code
at any given time. A situation may arise where the process running the cleanup
segfaults (ie same process, but different thread) such that the lockfile is not
deleted. If this should happen subsequent attempts to run the cleanup will
fail. To avoid this possibility a test has been added to check the age of the
lockfile. If it is more than 3600 seconds old it will be considered stale
and deleted. The next time filesession cleanup runs it should succeed.

Modified:
    httpd/mod_python/trunk/lib/python/mod_python/Session.py

Modified: httpd/mod_python/trunk/lib/python/mod_python/Session.py
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/lib/python/mod_python/Session.py?rev=327728&r1=327727&r2=327728&view=diff
==============================================================================
--- httpd/mod_python/trunk/lib/python/mod_python/Session.py (original)
+++ httpd/mod_python/trunk/lib/python/mod_python/Session.py Sat Oct 22 19:05:01 2005
@@ -505,7 +505,20 @@
     try:
         lockfp = os.open(lockfile, os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0660) 
     except:
-        req.log_error('FileSession cleanup: another process is already running.',
+        # check if it's a stale lockfile
+        mtime = os.stat(lockfile).st_mtime
+        if mtime < (time.time() - 3600):
+            # lockfile is over an hour old so it's likely stale.
+            # Even though there may not be another cleanup process running,
+            # we are going to defer running the cleanup at this time.
+            # Short circuiting this cleanup just makes the code a little cleaner.
+            req.log_error('FileSession cleanup: stale lockfile found - deleting it',
+                        apache.APLOG_NOTICE)
+            # Remove the stale lockfile so the next call to filesession_cleanup
+            # can proceed.
+            os.remove(lockfile)
+        else:
+            req.log_error('FileSession cleanup: another process is already running',
                         apache.APLOG_NOTICE)
         return