[njs] Modules: fixed clear() method of a shared dictionary without timeout.

Dmitry Volyntsev xeioex at nginx.com
Thu Mar 21 01:29:06 UTC 2024


details:   https://hg.nginx.org/njs/rev/f632fe16ba05
branches:  
changeset: 2303:f632fe16ba05
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Tue Mar 19 21:05:51 2024 -0700
description:
Modules: fixed clear() method of a shared dictionary without timeout.

Previously, the code did not unlock the rwlock when a dict was empty.

The issue was introduced in 4a15613f4e8b (0.8.3).

This closes issue #699 on Github.

diffstat:

 nginx/ngx_js_shared_dict.c |  4 +++-
 nginx/t/js_shared_dict.t   |  1 +
 2 files changed, 4 insertions(+), 1 deletions(-)

diffs (32 lines):

diff -r 85313a068147 -r f632fe16ba05 nginx/ngx_js_shared_dict.c
--- a/nginx/ngx_js_shared_dict.c	Mon Mar 18 22:24:57 2024 -0700
+++ b/nginx/ngx_js_shared_dict.c	Tue Mar 19 21:05:51 2024 -0700
@@ -479,7 +479,7 @@ njs_js_ext_shared_dict_clear(njs_vm_t *v
         rbtree = &dict->sh->rbtree;
 
         if (rbtree->root == rbtree->sentinel) {
-            return NJS_OK;
+            goto done;
         }
 
         for (rn = ngx_rbtree_min(rbtree->root, rbtree->sentinel);
@@ -494,6 +494,8 @@ njs_js_ext_shared_dict_clear(njs_vm_t *v
         }
     }
 
+done:
+
     ngx_rwlock_unlock(&dict->sh->rwlock);
 
     njs_value_undefined_set(retval);
diff -r 85313a068147 -r f632fe16ba05 nginx/t/js_shared_dict.t
--- a/nginx/t/js_shared_dict.t	Mon Mar 18 22:24:57 2024 -0700
+++ b/nginx/t/js_shared_dict.t	Tue Mar 19 21:05:51 2024 -0700
@@ -266,6 +266,7 @@ EOF
 
     function set_clear(r) {
         var dict = ngx.shared.no_timeout;
+        dict.clear();
         dict.set("test", "test value");
         dict.set("test1", "test1 value");
         dict.clear();


More information about the nginx-devel mailing list