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

attempt to index local 'slot_item' (a nil value) #25

Open
pzystorm opened this issue May 29, 2019 · 1 comment
Open

attempt to index local 'slot_item' (a nil value) #25

pzystorm opened this issue May 29, 2019 · 1 comment

Comments

@pzystorm
Copy link

Hi
I have setup everything as described.
I call the website f.ex. like this: www.foo.de/ratechecker?token=foo
Inside nginx i have defined the location /ratechecker with redis like your example:

        location /ratechecker {
          default_type 'text/plain';
          content_by_lua_block {
            local redis_client = redis_cluster:new(config)
            local rate, err = redis_rate.measure(redis_client, ngx.var.arg_token)
            if err then
              ngx.log(ngx.ERR, "err: ", err)
              ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
            end
            if rate > 10 then
              ngx.exit(ngx.HTTP_FORBIDDEN)
            end
            ngx.say(rate)
          }
        }

Now I get the error

019/05/29 16:42:34 [error] 10383#10383: *26 lua entry thread aborted: runtime error: /usr/local/openresty/lualib/resty-redis-cluster.lua:506: attempt to index local 'slot_item' (a nil value)
stack traceback:
coroutine 0:
        /usr/local/openresty/lualib/resty-redis-cluster.lua: in function 'commit_pipeline'
        /usr/local/openresty/lualib/resty-redis-rate.lua:19: in function 'measure'
        content_by_lua(nginx.conf:160):3: in main chunk, client: 10.51.21.110, server: foo.de, request: "GET /ratechecker?token=foo HTTP/1.1", host: "foo.de:8111"

Line 506 is this last line of this code passage:

        _reqs[i].origin_index = i
        local key = _reqs[i].key
        local slot = redis_slot(tostring(key))
        local slot_item = slots[slot]

        local ip, port, slave, err = pick_node(self, slot_item.serv_list, slot, magicRandomPickupSeed)

Between the empty line I have inserted this:

        ngx.say("ok " .. slot .. " ok " .. key)
        ngx.exit(200)

It outputs:
ok 12182 ok ngx_rate_measuring_{foo}_20
But slot_item is nil...

Can someone help me?
Whats wrong?

@leandromoreira
Copy link
Owner

Hi there @pzystorm how are you? are you using redis cluster?

Did you allocated memory for the slots:

 lua_shared_dict redis_cluster_slot_locks 100k;

Can you also make it work through the docker-compose we provided? If yes then it might be related to something missing in your nignx.conf you can look at the example to see what's missing.

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

2 participants