ngx_ext_rename_file: remove the target file if ngx_copy_file() fails

Mindaugas Rasiukevicius rmind at
Thu Jul 9 13:10:48 UTC 2015


Some background: nginx 1.9.2, used as a cache, can get into the state
when it stops evicting the objects and eventually stops caching without
being able to recover.  This happens when the disk is full.  Consider the
following nginx.conf fragment:

proxy_cache_path /cache/nginx levels=1:2
        keys_zone=c3:4096m max_size=8500g
        inactive=30d use_temp_path=on;
proxy_temp_path /cache/nginx-tmp 1 2;

The disk is filled because the workers have been fetching the data from
the backend faster than the cache manager is able to evict:

$ df -h | grep cache
/dev/sdb1             8.7T  8.7T   16M 100% /cache
tmpfs                 2.0G     0  2.0G   0% /cache/nginx-tmp

Since /cache and /cache/nginx-tmp are separate mount points, nginx has to
perform copy instead of rename.  The copy functions fails due to ENOSPC,
but the ngx_ext_rename_file() does not clean up the failed target.  At this
point, based on ngx_http_file_cache_sh_t::size, the cache manager believes
that the 8.5 TB threshold has not been crossed and nginx fails to recover.

Please find the patch attached.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ngx_ext_rename_file.patch
URL: <>

More information about the nginx-devel mailing list