Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ngx.shared.DICT:ttl() returns 0 for the exipred key #453

Open
3 tasks done
chobits opened this issue Dec 25, 2023 · 0 comments
Open
3 tasks done

ngx.shared.DICT:ttl() returns 0 for the exipred key #453

chobits opened this issue Dec 25, 2023 · 0 comments

Comments

@chobits
Copy link

chobits commented Dec 25, 2023

Hi guys,

I found in some scenario, the ngx.shared.DICT:ttl(key) will return 0 (key will never expire) for the expired key. Is this an intentional design or a bug?


The return value 0 of ngx.shared.DICT:ttl(key) in lua-nginx-module doc means this key would never expire.

A value of 0 means that the item will never expire.

But sometimes if the key expires, it still returns 0 value

Steps to reproduce

  1. source
$ cat ttl_0.sh
resty --shdict "hello 10m" -e '
local dict = ngx.shared.hello

dict:set("foo", "bar", 0.002)

for i = 1, 2 do
  ngx.sleep(0.001)
  local ttl = dict:ttl("foo")
  print(ttl)
  assert(ttl ~= 0)
end
'
  1. run it mutiple times, you'll get the assertion failure
$ sh ttl_0.sh
0.001
0
ERROR: (command line -e):10: assertion failed!
stack traceback:
        (command line -e):10: in function 'inline_gen'
        init_worker_by_lua(nginx.conf:142):44: in function <init_worker_by_lua(nginx.conf:142):43>
        [C]: in function 'xpcall'
        init_worker_by_lua(nginx.conf:142):52: in function <init_worker_by_lua(nginx.conf:142):50>

  • The exact version of the related software, including but not limited to the OpenResty version
    (if any), the NGINX core version, the ngx_lua module version(via openresty -V or nginx -V),
    and the lua-resty-core version(via resty -e 'print(require("resty.core").version)'),
    and your operating system version(via uname -a).
 $ resty -v
resty 0.29
nginx version: openresty/1.21.4.3 (no pool)
built with OpenSSL 3.1.4 24 Oct 2023
TLS SNI support enabled
configure arguments: --prefix=/private/var/tmp/_bazel_xc/e6d31d9d1855f25ff93b432735e02c28/execroot/kong/bazel-out/darwin_arm64-fastbuild/bin/external/openresty/openresty.build_tmpdir/openresty/nginx --with-debug --with-cc-opt='-DNGX_LUA_USE_ASSERT -DNGX_LUA_ABORT_AT_PANIC -O2 -I/private/var/tmp/_bazel_xc/e6d31d9d1855f25ff93b432735e02c28/execroot/kong/bazel-out/darwin_arm64-fastbuild/bin/external/openresty/openresty.ext_build_deps/pcre/include -I/private/var/tmp/_bazel_xc/e6d31d9d1855f25ff93b432735e02c28/execroot/kong/bazel-out/darwin_arm64-fastbuild/bin/external/openresty/openresty.ext_build_deps/openssl/include -I/private/var/tmp/_bazel_xc/e6d31d9d1855f25ff93b432735e02c28/execroot/kong/bazel-out/darwin_arm64-fastbuild/bin/external/openresty/openresty.ext_build_deps/luajit/include -DNGX_LUA_USE_ASSERT -DNGX_LUA_ABORT_AT_PANIC -g -O0 -DNGX_WASM_HOST_PROPERTY_NAMESPACE=kong' --add-module=../ngx_devel_kit-0.3.2 --add-module=../echo-nginx-module-0.63 --add-module=../ngx_lua-0.10.25 --add-module=../headers-more-nginx-module-0.34 --add-module=../ngx_stream_lua-0.0.13 --with-ld-opt='-Wl,-rpath,/Users/xc/work/dev/kong/bazel-bin/build/kong-dev/openresty/luajit/lib -L/private/var/tmp/_bazel_xc/e6d31d9d1855f25ff93b432735e02c28/execroot/kong/bazel-out/darwin_arm64-fastbuild/bin/external/openresty/openresty.ext_build_deps/pcre/lib -L/private/var/tmp/_bazel_xc/e6d31d9d1855f25ff93b432735e02c28/execroot/kong/bazel-out/darwin_arm64-fastbuild/bin/external/openresty/openresty.ext_build_deps/openssl/lib -L/private/var/tmp/_bazel_xc/e6d31d9d1855f25ff93b432735e02c28/execroot/kong/bazel-out/darwin_arm64-fastbuild/bin/external/openresty/openresty.ext_build_deps/luajit/lib -Wl,-rpath,/Users/xc/work/dev/kong/bazel-bin/build/kong-dev/kong/lib -Wl,-rpath,/Users/xc/work/dev/kong/bazel-bin/build/kong-dev/openresty/lualib' --with-pcre-jit --with-http_ssl_module --with-http_sub_module --with-http_realip_module --with-http_stub_status_module --with-http_v2_module --with-stream_realip_module --with-stream_ssl_preread_module --add-module=/private/var/tmp/_bazel_xc/e6d31d9d1855f25ff93b432735e02c28/execroot/kong/external/lua-kong-nginx-module --add-module=/private/var/tmp/_bazel_xc/e6d31d9d1855f25ff93b432735e02c28/execroot/kong/external/lua-kong-nginx-module/stream --add-module=/private/var/tmp/_bazel_xc/e6d31d9d1855f25ff93b432735e02c28/execroot/kong/external/lua-resty-lmdb --add-module=/private/var/tmp/_bazel_xc/e6d31d9d1855f25ff93b432735e02c28/execroot/kong/external/lua-resty-events --with-compat --add-dynamic-module=/private/var/tmp/_bazel_xc/e6d31d9d1855f25ff93b432735e02c28/execroot/kong/external/ngx_wasm_module --with-stream --with-stream_ssl_module
  • A minimal and standalone test case that others can easily run on their side and
    reproduce the issue you are seeing.
  • Do not simply say "something is broken" or "something does not work". Always provide
    as much details as possible. Always describe the symptoms and your expected results.

You can (temporarily) enable the nginx debugging logs to see the internal workings
of NGINX in your nginx''s error.log file. See http://nginx.org/en/docs/debugging_log.html
The same instructions apply equally well to OpenResty.

If you are seeing crashes, please provide the full backtrace for the crash. See
https://www.nginx.com/resources/wiki/start/topics/tutorials/debugging/#core-dump
for more details.

Thanks for your cooperation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant