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

[TT-13402] Rate limit does not get reset when using more than 1 gateway pods in kubernetes #5919

Open
utkarsh079 opened this issue Jan 4, 2024 · 1 comment

Comments

@utkarsh079
Copy link

Branch/Environment/Version

  • Branch/Version: Master
  • Environment: kubernetes

Describe the bug
I am configuring 100 rate per 60 seconds with a python plugin.
When I am using a single gateway pod everything is working fine. but when we scale up number of pods we are seeing that

for first 60 seconds we are getting 200
but after that, rate never gets reset. We are constantly getting 429s
My middleware is like this

from tyk.decorators import *
from gateway import TykGateway as tyk
from policies import policy
import datetime
import os
import sys

parent_dir = os.path.abspath(os.path.dirname(__file__))
vendor_dir = os.path.join(parent_dir, 'vendor')
sys.path.append(vendor_dir)

@Hook
def MyAuthMiddleware(request, session, metadata, spec):
    tyk.log("Starting Auth middleware", "info")
    default_policy = policy["voyages"]["default"]
    try:
        tyk.log(f"request ip is {request.get_header('X-Real-Ip')}", "info")
        if str(request.get_header('X-Real-Ip')) != '':
            metadata["token"] = request.get_header('X-Real-Ip')
            session.rate = default_policy["rate"]
            session.per = default_policy["per"]
            session.quota_max = default_policy["quota_max"]
            session.quota_renewal_rate = default_policy["quota_renewal_rate"]
            session.session_lifetime = 3600
    except:
        tyk.log("something went wrong", "info")
    return request, session, metadata

Reproduction steps
Steps to reproduce the behavior:

  1. Scale tyk gateway pods to 2
  2. Deploy the plugin to do rate limiting with ip

Actual behavior
API keeps on returning 429 even after the rate limit interval (60 seconds) has passed
Expected behavior
Rate limit for a particular ip should get reset after 60 seconds

Additional context
Tyk version: CE (v5.2.3)

@utkarsh079 utkarsh079 added the bug label Jan 4, 2024
@linhhahoang1999
Copy link

are you using ratelimit with redis? If so, can you try this PR to solve your problem?

@andyo-tyk andyo-tyk changed the title Rate limit does not get reset when using more than 1 gateway pods in kubernetes [TT-13402] Rate limit does not get reset when using more than 1 gateway pods in kubernetes Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants