openresty / openresty/lua-nginx-module

ngx.shared.DICT.get_stale(key) can`t get stale data

Open
#1,281 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
11.8k
Forks
2.1k
Avg merge
6h 1m
Merged PRs (30d)
6

Description

i use shcache [https://github.com/mtourne/ngx.shcache], which is simple cache object atop ngx.shared.DICT。

i set expire time is 10s。 in 0s, when i send a request, its noraml that no caches in DICT。so log like this 2018/03/20 20:18:33 [error] 16546#16546: *7 [lua] shcache.lua:327: _get(): lua----------------------test0: 0, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:18:33 [error] 16546#16546: *7 [lua] shcache.lua:328: _get(): lua----------------------test1: nil, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:18:33 [error] 16546#16546: *7 [lua] shcache.lua:329: _get(): lua----------------------test2: nil, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:18:33 [error] 16546#16546: *7 [lua] shcache.lua:355: load(): lua----------------------001: nil, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:18:33 [error] 16546#16546: *7 [lua] shcache.lua:327: _get(): lua----------------------test0: 0, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:18:33 [error] 16546#16546: *7 [lua] shcache.lua:328: _get(): lua----------------------test1: nil, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:18:33 [error] 16546#16546: *7 [lua] shcache.lua:329: _get(): lua----------------------test2: nil, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:18:33 [error] 16546#16546: *7 [lua] shcache.lua:416: load(): lua----------------------005, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:18:33 [error] 16546#16546: *7 [lua] shcache.lua:327: _get(): lua----------------------test0: 0, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:18:33 [error] 16546#16546: *7 [lua] shcache.lua:328: _get(): lua----------------------test1: nil, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:18:33 [error] 16546#16546: *7 [lua] shcache.lua:329: _get(): lua----------------------test2: nil, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:18:33 [error] 16546#16546: *7 [lua] shcache.lua:355: load(): lua----------------------001: nil, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:18:33 [error] 16546#16546: *7 [lua] shcache.lua:327: _get(): lua----------------------test0: 0, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:18:33 [error] 16546#16546: *7 [lua] shcache.lua:328: _get(): lua----------------------test1: nil, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:18:33 [error] 16546#16546: *7 [lua] shcache.lua:329: _get(): lua----------------------test2: nil, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:18:33 [error] 16546#16546: *7 [lua] shcache.lua:416: load(): lua----------------------005, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"`

which test0 means llen(key), test1,test2 means get_stale(key)`s flags and stale or not , the logs meet my expections。

in the 10s , logs like this:
2018/03/20 20:19:06 [error] 16546#16546: *7 [lua] shcache.lua:327: _get(): lua----------------------test0: nil, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:19:06 [error] 16546#16546: *7 [lua] shcache.lua:328: _get(): lua----------------------test1: 1, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:19:06 [error] 16546#16546: *7 [lua] shcache.lua:329: _get(): lua----------------------test2: false, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:19:06 [error] 16546#16546: *7 [lua] shcache.lua:355: load(): lua----------------------001: 1, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:19:06 [error] 16546#16546: *7 [lua] shcache.lua:359: load(): lua----------------------002, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:19:06 [error] 16546#16546: *7 [lua] shcache.lua:327: _get(): lua----------------------test0: nil, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:19:06 [error] 16546#16546: *7 [lua] shcache.lua:328: _get(): lua----------------------test1: 1, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:19:06 [error] 16546#16546: *7 [lua] shcache.lua:329: _get(): lua----------------------test2: false, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:19:06 [error] 16546#16546: *7 [lua] shcache.lua:355: load(): lua----------------------001: 1, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:19:06 [error] 16546#16546: *7 [lua] shcache.lua:359: load(): lua----------------------002, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"

it also meets。

but after 10s, logs like this:
2018/03/20 20:19:18 [error] 16546#16546: *7 [lua] shcache.lua:327: _get(): lua----------------------test0: 0, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:19:18 [error] 16546#16546: *7 [lua] shcache.lua:328: _get(): lua----------------------test1: 1, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:19:18 [error] 16546#16546: *7 [lua] shcache.lua:329: _get(): lua----------------------test2: true, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:19:18 [error] 16546#16546: *7 [lua] shcache.lua:355: load(): lua----------------------001: nil, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:19:18 [error] 16546#16546: *7 [lua] shcache.lua:327: _get(): lua----------------------test0: 0, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:19:18 [error] 16546#16546: *7 [lua] shcache.lua:328: _get(): lua----------------------test1: nil, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:19:18 [error] 16546#16546: *7 [lua] shcache.lua:329: _get(): lua----------------------test2: nil, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:19:18 [error] 16546#16546: *7 [lua] shcache.lua:416: load(): lua----------------------005, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:19:18 [error] 16546#16546: *7 [lua] shcache.lua:327: _get(): lua----------------------test0: 0, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:19:18 [error] 16546#16546: *7 [lua] shcache.lua:328: _get(): lua----------------------test1: nil, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:19:18 [error] 16546#16546: *7 [lua] shcache.lua:329: _get(): lua----------------------test2: nil, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:19:18 [error] 16546#16546: *7 [lua] shcache.lua:355: load(): lua----------------------001: nil, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:19:18 [error] 16546#16546: *7 [lua] shcache.lua:327: _get(): lua----------------------test0: 0, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:19:18 [error] 16546#16546: *7 [lua] shcache.lua:328: _get(): lua----------------------test1: nil, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:19:18 [error] 16546#16546: *7 [lua] shcache.lua:329: _get(): lua----------------------test2: nil, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"
2018/03/20 20:19:18 [error] 16546#16546: *7 [lua] shcache.lua:416: load(): lua----------------------005, client: ::ffff:10.74.57.144, server: , request: "GET /api/test007/v1 HTTP/1.1", host: "10.74.151.122"

you can see only a request can get stale data but the other get nothing from the function get_stale.
so i wonder why the second request can`t get stale data.

ps. it seems that i send two requests , but actually , i just send one http request. the first was router for http request and the second was request for http request。 so we can see two keys in logs。

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the ngx.shared.DICT:get_stale(key) behavior and the shcache.lua call sites around lines 327-416 shown in the report. Reproduce the two-key request sequence with a 10-second expiration, then inspect how stale flags and values are handled; done means the reported second lookup behavior is explained and covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, nginx
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.