ExHammer / hammer-backend-redis

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

Too many attempts to create bucket #26

Closed rafaelsiqueira closed 2 years ago

rafaelsiqueira commented 2 years ago

Hi folks,

I'm running this backend in production and sometimes we're getting this error:

GenServer #PID<0.20261.1> terminating
** (RuntimeError) Failed to count hit: too many attempts to create bucket.
    (hammer_backend_redis 6.1.0) lib/hammer_backend_redis.ex:199: Hammer.Backend.Redis.do_count_hit/6
    (hammer_backend_redis 6.1.0) lib/hammer_backend_redis.ex:144: Hammer.Backend.Redis.handle_call/3
    (stdlib 3.13.1) gen_server.erl:706: :gen_server.try_handle_call/4
    (stdlib 3.13.1) gen_server.erl:735: :gen_server.handle_msg/6
    (stdlib 3.13.1) proc_lib.erl:226: :proc_lib.init_p_do_apply/3

This could be a race condition since we're using more than 1 node.

I was wondering...

Why are we raising an error instead of return {:error, :too_many_attempts}. This makes things harder to handle.

sorliem commented 2 years ago

Running into same issue