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

Reset is not working with count.md code #45

Open
darpangupta12 opened this issue Jun 13, 2019 · 0 comments
Open

Reset is not working with count.md code #45

darpangupta12 opened this issue Jun 13, 2019 · 0 comments

Comments

@darpangupta12
Copy link

For Nginx rate limiting, we are using code written on count.md. Also, we are using count.lua library.
Below code, giving counter value from 199 to 1 from line
local delay, err = lim:incoming(key, true)
After that, above line giving rejected error hence, it returning 503 error.
So, reset is not working in time_window & getting rejected value in err.Please check count.lua library as well.

Refer Code :-
local lim, err = limit_count.new("my_limit_count_store", 200, 1)
ngx.log(ngx.ERR, "lim instance value: ", err)
if not lim then
--ngx.log(ngx.ERR, "failed to instantiate a resty.limit.conn object: ", err)
return ngx.exit(500)
end
--if header_authorization then
local base64_enc = string.sub(header_authorization, 7)
local base64_dec = ngx.decode_base64(base64_enc)
ngx.log(ngx.ERR, "base64_dec value: ", base64_dec)
local key = base64_dec
local delay, err = lim:incoming(key, true)
ngx.log(ngx.ERR,"new instance value: ",err)

      if not delay then
                if err == "rejected" then
                    ngx.log(ngx.ERR, "coming to this block: ", err)
                    ngx.header["X-RateLimit-Limit"] = "200"
                    ngx.header["X-RateLimit-Remaining"] = 0
                    return ngx.exit(503)
                end
          --      ngx.log(ngx.ERR, "failed to limit req: ", err)
                return ngx.exit(500)
      end

    local remaining = err
    ngx.log(ngx.ERR, "remaining value: ", remaining)

    ngx.header["X-RateLimit-Limit"] = "200"
    ngx.header["X-RateLimit-Remaining"] = remaining
    ngx.log(ngx.ERR, "X-RateLimit-Remaining: ", ngx.header["X-RateLimit-Remaining"])
monkeyDluffy6017 pushed a commit to monkeyDluffy6017/lua-resty-limit-traffic that referenced this issue Apr 19, 2023
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