ExHammer / hammer-backend-redis

A Redis backend for for the Hammer rate-limiter
https://hexdocs.pm/ExHammer/hammer-backend-redis
MIT License
43 stars 31 forks source link

Having trouble connecting with Redis on prod. #78

Open talhaazeemmughal opened 1 month ago

talhaazeemmughal commented 1 month ago

Describe the bug i have redix library defined in my config and i also have hammer one defined as below:

config :hammer,
  backend:
    {Hammer.Backend.Redis,
     [
       expiry_ms: :timer.hours(24),
       redix_config: [
         host: System.get_env("HOST", "127.0.0.1"),
         port: System.get_env("PORT", "6379") |> String.to_integer(),
         password: System.get_env("PASSWORD"),
         ssl: System.get_env("SSL", "false") == "true"
       ],
       pool_size: 30,
       timeout: 5000
     ]}

config :redix,
  url: System.get_env("REDIS_URL", "redis://127.0.0.1:6379"),
  pool_size: 30

i am also adding this to redix and hammer library while booting the app for socket_opts:

[
      customize_hostname_check: [
        match_fun: :public_key.pkix_verify_hostname_match_fun(:https)
      ]
]

now redix is getting connected properly as i ran redix ping command i got pong in response but when i execute Hammer.check_rate in prod iex. it gives redis error saying connection closed. i am kind of stuck here.

** Provide the following details

Expected behavior Hammer.check_rate should be connecting with redis and giving the required output like {:allow, count}, {:deny, limit}

Actual behavior It actually gives the error tuple {:error, err} and err variable says redis connection closed.

talhaazeemmughal commented 1 month ago

i think i need to pass this (since i am using AWS Elasticache Redis Instance)

[
      customize_hostname_check: [
        match_fun: :public_key.pkix_verify_hostname_match_fun(:https)
      ]
]

to the redix_config that i am passing to the hammer library, how can i do that?

image
epinault commented 4 weeks ago

Hello! interesting! I use also Elasticache and we don t have that issue. Maybe depends on some configuration you might have setup with the Elasticache but that seems to make sense . If you have time to make an MR, feel free to open one. I ll see tomorrow if I can block sometime to create one and release something

talhaazeemmughal commented 4 weeks ago

Hello! interesting! I use also Elasticache and we don t have that issue. Maybe depends on some configuration you might have setup with the Elasticache but that seems to make sense . If you have time to make an MR, feel free to open one. I ll see tomorrow if I can block sometime to create one and release something

@epinault also i think generating MR will not help me since i am on elixir 1.10.4-otp-22 and hammer 6.2.1 is using elixir 1.13 while the hammer_backend_redis 6.1.2 is using elixir 1.12 and we are upgrading it to use elixir 1.12.

another thing to note over here is that if i pass verify: :verify_none in socket_opts then it works fine.