mod_disk_cache cannot update cache for expired content (win32) There is a problem with using mod_disk_cache in conjonction of mod_proxy. When a file is expired in the cache, mod_disk_cache doesn't handle the backend update correctly. This leads to 2 differents problems: 1) The cache won't never been updated and you're loosing benefits of caching. 2) It leaves a tempfile in CacheRoot dir, making the CacheRoot dir bigger than expected. Messages that are displayed in error.log: ========================================== [Wed Mar 29 10:41:40 2006] [error] (OS 5)Accès refusé. : disk_cache: rename tempfile to hdrsfile failed: C:/apache_cache/aptmpcBQArf -> C:/apache_cache/M/2fl@WQwwEqpEKxjyw7VFA.header Steps to reproduce: ========================================== httpd.conf: #LogLevel warn Listen 80 LoadModule authz_host_module modules/mod_authz_host.so LoadModule cache_module modules/mod_cache.so LoadModule disk_cache_module modules/mod_disk_cache.so LoadModule log_config_module modules/mod_log_config.so LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module modules/mod_proxy_http.so LoadModule ssl_module modules/mod_ssl.so LoadModule rewrite_module modules/mod_rewrite.so LoadModule include_module modules/mod_include.so LoadModule headers_module modules/mod_headers.so LoadModule setenvif_module modules/mod_setenvif.so LoadModule unique_id_module modules/mod_unique_id.so Timeout 300 KeepAlive On MaxKeepAliveRequests 10000 KeepAliveTimeout 15 <IfModule mpm_winnt.c> ThreadsPerChild 250 MaxRequestsPerChild 0 </IfModule> ProxyVia on SSLProxyEngine on SSLSessionCache shm:C:/Apache/2.2.0/logs/ssl_gcache_data(1048576) ServerRoot "C:/Apache/2.2.0" DocumentRoot "C:/Apache/2.2.0" ServerName localhost:80 # On ne doit pas avoir d'éléments variables dans le cache. Header unset Vary Header unset Expires CacheIgnoreHeaders Set-Cookie CacheIgnoreHeaders RequestID CacheIgnoreHeaders TimeReq CacheIgnoreHeaders User-Agent CacheIgnoreHeaders Accept-Encoding CacheIgnoreHeaders Warning CacheIgnoreHeaders Via # Forcer IE à cacher les éléments statiques. SetEnvIf Request_URI "\.css$" force-no-vary SetEnvIf Request_URI "\.gif$" force-no-vary SetEnvIf Request_URI "\.hta$" force-no-vary SetEnvIf Request_URI "\.htm$" force-no-vary SetEnvIf Request_URI "\.html$" force-no-vary SetEnvIf Request_URI "\.jpg$" force-no-vary SetEnvIf Request_URI "\.js$" force-no-vary SetEnvIf Request_URI "\.vbs$" force-no-vary <Directory /> Options FollowSymLinks AllowOverride None Order deny,allow Deny from all </Directory> <Directory "C:/Apache/2.2.0/htdocs"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> <IfModule dir_module> DirectoryIndex index.html </IfModule> <FilesMatch "^\.ht"> Order allow,deny Deny from all </FilesMatch> ErrorLog logs/error.log <IfModule log_config_module> LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %b" common <IfModule logio_module> # You need to enable mod_logio.c to use %I and %O LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio </IfModule> CustomLog logs/access.log common </IfModule> <IfModule alias_module> ScriptAlias /cgi-bin/ "C:/Apache/2.2.0/cgi-bin/" </IfModule> <Directory "C:/Apache/2.2.0/cgi-bin"> AllowOverride None Options None Order allow,deny Allow from all </Directory> DefaultType text/plain <IfModule mime_module> TypesConfig conf/mime.types AddType application/x-compress .Z AddType application/x-gzip .gz .tgz </IfModule> EnableMMAP off EnableSendfile off Win32DisableAcceptEx <IfModule ssl_module> SSLRandomSeed startup builtin SSLRandomSeed connect builtin </IfModule> Listen 81 <VirtualHost *:81> RequestHeader set TimeReq "%t" RequestHeader set RequestID "%{UNIQUE_ID}e" CacheEnable disk / CacheMaxExpire 10 CacheDefaultExpire 10 CacheLastModifiedFactor 10000000.0 CacheRoot "C:/apache_cache" CacheDirLength 1 CacheDirLevels 1 RewriteEngine On RewriteRule ^/(.*)$ http://some.site.com/$1 [P,L] ProxyPassReverse / http://some.site.com/ CustomLog "| 'C:/Apache/2.2.0/bin/rotatelogs.exe' -l 'logs/vhost81_%Y%m%d.log' 86400" common </VirtualHost> Then issue this command: bin\ab.exe -n 10000 -c 1024 -k -d http://some.site.com/some/file.txt As soon as the file will be expired, you will see the problem.
mod_disk_cache makes several assumptions on how unix file systems operate, and how it is safe to move files, even if they are open. Win32 doesn't really support all of these concepts. I am not sure if we ever plan to support mod_disk_cache on win32, at least in the current incarnation. (Patches welcome of course)
Created attachment 21858 [details] Patch which close opened files (unlock) before renaming Th problem is that the function cache_select (cache_storage.c) makes some return on error after the call to open_entity (provider) without taking care of opened files by this last function. So to fix this behaviour, the patch add a new function to sub provider which is intended to close potential opened handles. And this function is call before each returns on error. So, this patch need to act on 3 modules mod_cache, mod_disk_cache and mod_mem_cache. About mod_mem_cache, it needs to add the new function even if it does nothing.
I applied the patch bug found that I still had files being left open. In addition to the patch in mod_disk_cache.c I made the following changes : - set the header and body file handle to null after it's closed in multiple places - initialized the two handles to null in open_entity - in remove_entity close any open handles.
Please help us to refine our list of open and current defects; this is a mass update of old and inactive Bugzilla reports which reflect user error, already resolved defects, and still-existing defects in httpd. As repeatedly announced, the Apache HTTP Server Project has discontinued all development and patch review of the 2.2.x series of releases. The final release 2.2.34 was published in July 2017, and no further evaluation of bug reports or security risks will be considered or published for 2.2.x releases. All reports older than 2.4.x have been updated to status RESOLVED/LATER; no further action is expected unless the report still applies to a current version of httpd. If your report represented a question or confusion about how to use an httpd feature, an unexpected server behavior, problems building or installing httpd, or working with an external component (a third party module, browser etc.) we ask you to start by bringing your question to the User Support and Discussion mailing list, see [https://httpd.apache.org/lists.html#http-users] for details. Include a link to this Bugzilla report for completeness with your question. If your report was clearly a defect in httpd or a feature request, we ask that you retest using a modern httpd release (2.4.33 or later) released in the past year. If it can be reproduced, please reopen this bug and change the Version field above to the httpd version you have reconfirmed with. Your help in identifying defects or enhancements still applicable to the current httpd server software release is greatly appreciated.