Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions nginx/ngx_js_shared_dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -1618,6 +1618,7 @@ ngx_js_dict_delete(njs_vm_t *vm, ngx_js_dict_t *dict, ngx_str_t *key,
ngx_int_t rc;
ngx_msec_t now;
ngx_time_t *tp;
ngx_rbtree_key_t expire;
ngx_js_dict_node_t *node;

ngx_rwlock_wlock(&dict->sh->rwlock);
Expand All @@ -1629,7 +1630,11 @@ ngx_js_dict_delete(njs_vm_t *vm, ngx_js_dict_t *dict, ngx_str_t *key,
return NGX_DECLINED;
}

expire = 0;

if (dict->timeout) {
expire = node->expire.key;

ngx_rbtree_delete(&dict->sh->rbtree_expire, &node->expire);
}

Expand All @@ -1639,7 +1644,7 @@ ngx_js_dict_delete(njs_vm_t *vm, ngx_js_dict_t *dict, ngx_str_t *key,
tp = ngx_timeofday();
now = tp->sec * 1000 + tp->msec;

if (!dict->timeout || now < node->expire.key) {
if (!dict->timeout || now < expire) {
rc = ngx_js_dict_copy_value_locked(vm, dict, node, retval);

} else {
Expand Down Expand Up @@ -4041,6 +4046,7 @@ ngx_qjs_dict_delete(JSContext *cx, ngx_js_dict_t *dict, ngx_str_t *key,
JSValue ret;
ngx_msec_t now;
ngx_time_t *tp;
ngx_rbtree_key_t expire;
ngx_js_dict_node_t *node;

ngx_rwlock_wlock(&dict->sh->rwlock);
Expand All @@ -4052,7 +4058,11 @@ ngx_qjs_dict_delete(JSContext *cx, ngx_js_dict_t *dict, ngx_str_t *key,
return JS_UNDEFINED;
}

expire = 0;

if (dict->timeout) {
expire = node->expire.key;

ngx_rbtree_delete(&dict->sh->rbtree_expire, &node->expire);
}

Expand All @@ -4062,7 +4072,7 @@ ngx_qjs_dict_delete(JSContext *cx, ngx_js_dict_t *dict, ngx_str_t *key,
tp = ngx_timeofday();
now = tp->sec * 1000 + tp->msec;

if (!dict->timeout || now < node->expire.key) {
if (!dict->timeout || now < expire) {
ret = ngx_qjs_dict_copy_value_locked(cx, dict, node);

} else {
Expand Down
7 changes: 6 additions & 1 deletion nginx/t/js_shared_dict.t
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ EOF

$t->try_run('no js_shared_dict_zone');

$t->plan(59);
$t->plan(61);

###############################################################################

Expand Down Expand Up @@ -482,6 +482,11 @@ ok($ttl_incr_def >= 900000 && $ttl_incr_def <= 1000000,

like(http_get('/pop?dict=bar&key=FOO'), qr/zzz/, 'pop bar.FOO');
like(http_get('/pop?dict=bar&key=FOO'), qr/undefined/, 'pop deleted bar.FOO');

http_get('/set?dict=foo&key=POP&value=alive');
like(http_get('/pop?dict=foo&key=POP'), qr/alive/, 'pop unexpired foo.POP');
like(http_get('/pop?dict=foo&key=POP'), qr/undefined/, 'pop deleted foo.POP');

http_get('/set?dict=foo&key=BAR&value=xxx');
like(http_get('/clear?dict=foo'), qr/undefined/, 'clear foo');

Expand Down
Loading