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
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
'
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>
[x] 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).
[x] A minimal and standalone test case that others can easily run on their side and
reproduce the issue you are seeing.
[x] 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.
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.
But sometimes if the key expires, it still returns 0 value
Steps to reproduce
ngx_lua
module version(viaopenresty -V
ornginx -V
), and thelua-resty-core
version(viaresty -e 'print(require("resty.core").version)'
), and your operating system version(viauname -a
).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.