Tags: nginx-modules/ngx_cache_purge
Tags
ngx_cache_purge: correctness, safety, and build fixes Fix use-after-free race in process_queue(). The original code unlocked the queue mutex, walked the cache directory, then re-acquired the lock to free the item. Restructure to dequeue under the lock, unlock, then walk and free outside it. Fix vary_aware variant deletion leaving stale shared-memory state. The directory walk called ngx_delete_file() on variant files without updating their rbtree nodes, leaving fcn->exists set and cache->sh->size inflated until restart. Add ngx_cache_purge_invalidate_node() to clear each variant's rbtree metadata under shpool->mutex before the file is removed. Fix live reload not applying changed queue configuration. init_shm_zone() reused the existing queue on reload but never updated throttle_ms or queue_size; changes required a full restart to take effect. Fix integer overflow in shm_size arithmetic on 32-bit builds. Add NGX_CACHE_PURGE_QUEUE_SIZE_MAX and reject queue_size=0 in init_main_conf. Fix queue->size declared as ngx_atomic_t despite being accessed only under queue->mutex. Change to ngx_uint_t. Fix data race reading queue->size after unlock in the enqueue debug log. Fix mid-scope variable declarations in fastcgi, proxy, scgi, and uwsgi handlers to comply with gnu89. Replace magic constant 6 (KEY: header offset) with named constant NGX_CACHE_PURGE_KEY_HDR_OFFSET. Add NULL guard for cplcf->conf in the access handler. Mark response size globals const. Remove redundant variables in send_response(). Fix config shebang from bash to sh; remove write to $NGX_AUTOCONF_ERR which is reserved for the nginx build system. Add basic.t TEST 15 covering the vary_aware purge path. Add purge_servroot() to run_tests.sh to clean up between prove invocations.
fix response_type context and duplicate detection The cache_purge_response_type directive had a flawed duplicate detection guard that only checked for NGX_HTTP_LOC_CONF. This silently allowed duplicate directives in http and server contexts to overwrite previous values without throwing a configuration error. Additionally, a defunct guard attempting to check for NGX_HTTP_MODULE was comparing context flags against module-type magic bits, rendering it dead code. Remove the invalid NGX_HTTP_MODULE check and make duplicate detection unconditional. The directive is intentionally valid in http, server, and location contexts, and merge_loc_conf propagates the value downward appropriately. The README context documentation is updated to reflect this correctly. Furthermore, rename the internal configuration variable from resptype to response_type for clarity. Fix a typo in the response type macro definitions (NGX_REPONSE_TYPE_* to NGX_CACHE_PURGE_RESPONSE_TYPE_*) and properly namespace them. Clarify the documentation and internal comments for the cache_purge_throttle_ms directive. Bare integers are evaluated as milliseconds natively to match the directive's name, which differs from the standard nginx time parser, logging a startup warning. Add comprehensive test coverage in config.t to ensure proper context inheritance, duplicate config rejection, and explicit time suffix parsing.
PreviousNext