From: vitalyn Date: Fri, 2 Oct 2026 21:50:43 +0000 (+0200) Subject: Modules: fixed shared dict state save stuck forever X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=e374b09eb0e9139eae4ffcebd806f269d92b4d37;p=njs.git Modules: fixed shared dict state save stuck forever The "dirty" and "writing" flags of a shared dict were bit fields of the same word. ngx_js_dict_save() clears "writing" without holding the lock, while set(), incr(), delete() and clear() set "dirty" under the write lock in other workers. The two read-modify-write operations could interleave and leave "writing" set for good. After that, every save attempt returned NGX_AGAIN: the state file was never written again, and the save timer, re-armed every second and not cancelable, prevented any worker of the zone from finishing a graceful shutdown, regardless of worker_shutdown_timeout. The flag lives in shared memory, so it survived reloads. The fix is to store the flags in separate words. Co-Authored-By: Claude Opus 5.5 (1M context) This fixes #1136. --- diff --git a/nginx/ngx_js_shared_dict.c b/nginx/ngx_js_shared_dict.c index 2631f7e7..30de86bf 100644 --- a/nginx/ngx_js_shared_dict.c +++ b/nginx/ngx_js_shared_dict.c @@ -19,8 +19,8 @@ typedef struct { ngx_rbtree_t rbtree_expire; ngx_rbtree_node_t sentinel_expire; - unsigned dirty:1; - unsigned writing:1; + ngx_uint_t dirty; + ngx_uint_t writing; } ngx_js_dict_sh_t;