]> git.kaiwu.me - njs.git/commit
Modules: fixed shared dict state save stuck forever
authorvitalyn <jc@vitalyn.com>
Fri, 2 Oct 2026 21:50:43 +0000 (23:50 +0200)
committerDmitry Volyntsev <xeioexception@gmail.com>
Thu, 15 Oct 2026 01:49:05 +0000 (18:49 -0700)
commite374b09eb0e9139eae4ffcebd806f269d92b4d37
tree9102bb20a6829d925a22db2b6ebe6cc42051daa2
parent64f5c15ec8797947e18afe5ff1de04cbd963a7dd
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) <noreply@anthropic.com>
This fixes #1136.
nginx/ngx_js_shared_dict.c