[nginx] Cache: fixed race in ngx_http_file_cache_forced_expire().

Maxim Dounin mdounin at mdounin.ru
Tue Feb 1 14:48:18 UTC 2022


details:   https://hg.nginx.org/nginx/rev/dd718d1cef3c
branches:  
changeset: 8005:dd718d1cef3c
user:      Maxim Dounin <mdounin at mdounin.ru>
date:      Tue Feb 01 16:29:28 2022 +0300
description:
Cache: fixed race in ngx_http_file_cache_forced_expire().

During configuration reload two cache managers might exist for a short
time.  If both tried to delete the same cache node, the "ignore long locked
inactive cache entry" alert appeared in logs.  Additionally,
ngx_http_file_cache_forced_expire() might be also called by worker
processes, with similar results.

Fix is to ignore cache nodes being deleted, similarly to how it is
done in ngx_http_file_cache_expire() since 3755:76e3a93821b1.  This
was somehow missed in 7002:ab199f0eb8e8, when ignoring long locked
cache entries was introduced in ngx_http_file_cache_forced_expire().

diffstat:

 src/http/ngx_http_file_cache.c |  5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diffs (15 lines):

diff -r c0a432c0301b -r dd718d1cef3c src/http/ngx_http_file_cache.c
--- a/src/http/ngx_http_file_cache.c	Wed Jan 26 20:40:00 2022 +0300
+++ b/src/http/ngx_http_file_cache.c	Tue Feb 01 16:29:28 2022 +0300
@@ -1756,6 +1756,11 @@ ngx_http_file_cache_forced_expire(ngx_ht
             break;
         }
 
+        if (fcn->deleting) {
+            wait = 1;
+            break;
+        }
+
         p = ngx_hex_dump(key, (u_char *) &fcn->node.key,
                          sizeof(ngx_rbtree_key_t));
         len = NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t);



More information about the nginx-devel mailing list