Graham Leggett wrote:
> Andreas Steinmetz said:
> 
> 
>>The problem is that you can't remove directories with htcacheclean
>>without generating race conditions wrt. httpd.
> 
> 
> In this case the race in httpd should be fixed.
> 
> In theory, httpd should attempt to create the directory, then attempt to
> move the file to that directory. If the move fails, attempt to create a
> directory and move the file again, until successful or some sane max
> retries, in which case give up and don't cache the file.

Fix attached and compile tested against 2.1.6 alpha.

-- 
Andreas Steinmetz                       SPAMmers use [EMAIL PROTECTED]
--- httpd-2.1.6-alpha/modules/cache/mod_disk_cache.c.orig       2005-08-08 
21:52:24.000000000 +0200
+++ httpd-2.1.6-alpha/modules/cache/mod_disk_cache.c    2005-08-08 
22:12:14.000000000 +0200
@@ -736,6 +736,7 @@
 
     disk_cache_info_t disk_info;
     struct iovec iov[2];
+    int i;
 
     /* This is flaky... we need to manage the cache_info differently */
     h->cache_obj->info = *info;
@@ -774,7 +775,14 @@
 
             dobj->tfd = NULL;
 
-            rv = apr_file_rename(dobj->tempfile, dobj->hdrsfile, r->pool);
+            for (i = 0; i < 3; i++) {
+                rv = apr_file_rename(dobj->tempfile, dobj->hdrsfile, r->pool);
+                if (rv == APR_SUCCESS) {
+                    break;
+                }
+                apr_sleep(1000);
+                mkdir_structure(conf, dobj->hdrsfile, r->pool);
+            }
             if (rv != APR_SUCCESS) {
                 ap_log_error(APLOG_MARK, APLOG_DEBUG, rv, r->server,
                     "disk_cache: rename tempfile to varyfile failed: %s -> %s",
@@ -865,7 +873,14 @@
         mkdir_structure(conf, dobj->hdrsfile, r->pool);
     }
     
-    rv = apr_file_rename(dobj->tempfile, dobj->hdrsfile, r->pool);
+    for (i = 0; i < 3; i++) {
+        rv = apr_file_rename(dobj->tempfile, dobj->hdrsfile, r->pool);
+        if (rv == APR_SUCCESS) {
+            break;
+        }
+        apr_sleep(1000);
+        mkdir_structure(conf, dobj->hdrsfile, r->pool);
+    }
 
     if (rv != APR_SUCCESS) {
         ap_log_error(APLOG_MARK, APLOG_ERR, rv, r->server,

Reply via email to