ejfinneran / ratelimit

A Redis-backed rate limiter written in Ruby
MIT License
260 stars 57 forks source link

Upgrading to 1.1.0 breaks the count method #48

Open knightq opened 9 months ago

knightq commented 9 months ago

The count method (changed in 1.1.0) is no longer returning (or sometimes may return) a nil, while previously an integer was always returned.

andreasknoepfle commented 9 months ago

Hi @knightq can you give us some more details here? Ideally your version of redis used & a minimal example producing 0?

To me this seems weird, since from the lua script, that would mean that nothing is returned, but we should always return something there. Maybe the lua script silently errors and returns nil? Can you also check if there is something in the logs of redis (maybe it logs script errors somewhere).

renatovico commented 2 months ago

break the connection pool too

I setup Ratelimit with :

Ratelimit.new(rate_limit_key, {redis: Rails.cache.redis})

this implicit use the connection Pool

Backtrace:

undefined method `script' for #<ConnectionPool:0x00007f8729861b88 @size=5, @timeout=5, @auto_reload_after_fork=true, @available=#<ConnectionPool::TimedStack:0x00007f8729861a98 @create_block=#<Proc:0x00007f872b6a9938 /home/renato/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/activesupport-7.1.4/lib/active_support/cache/redis_cache_store.rb:153>, @created=1, @que=[#<Redis client v5.3.0 for redis://localhost:6379>], @max=5, @mutex=#<Thread::Mutex:0x00007f872b6a96e0>, @resource=#<Thread::ConditionVariable:0x00007f872b6a9438>, @shutdown_block=nil>, @key=:"pool-11400", @key_count=:"pool-11400-count"> /home/renato/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/ratelimit-1.1.0/lib/ratelimit.rb:165:in `load_scripts'
/home/renato/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/ratelimit-1.1.0/lib/ratelimit.rb:62:in `initialize'