rate_limit.py has bug caused by temporal sequence issues #11297

Closed
opened 2026-02-21 18:58:00 -05:00 by yindo · 0 comments
Owner

Originally created by @lennydou on GitHub (Mar 16, 2025).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.15.3,1.0.0,latest

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

file: api/core/app/features/rate_limiting/rate_limit.py

if use_local_value or not redis_client.exists(self.max_active_requests_key): with redis_client.pipeline() as pipe: pipe.set(self.max_active_requests_key, self.max_active_requests) pipe.expire(self.max_active_requests_key, timedelta(days=1)) pipe.execute() else: with redis_client.pipeline() as pipe: self.max_active_requests = int(redis_client.get(self.max_active_requests_key).decode("utf-8")) redis_client.expire(self.max_active_requests_key, timedelta(days=1))

The code first checks whether self.max_active_requests_key exists in Redis. If it does, it proceeds to read it. However, I encountered an intermittent bug. When checking for the existence of self.max_active_requests_key in Redis, it was indeed present. But by the time I attempted to read it from Redis, the key had expired.

As a result, redis_client.get(self.max_active_requests_key) returned none.

✔️ Expected Behavior

The process of checking for the existence of a key in Redis and then reading the key from Redis should be an atomic operation.

Actual Behavior

The process of checking for the existence of a key in Redis and then reading the key from Redis is not an atomic operation.

Originally created by @lennydou on GitHub (Mar 16, 2025). ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.15.3,1.0.0,latest ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce file: api/core/app/features/rate_limiting/rate_limit.py ` if use_local_value or not redis_client.exists(self.max_active_requests_key): with redis_client.pipeline() as pipe: pipe.set(self.max_active_requests_key, self.max_active_requests) pipe.expire(self.max_active_requests_key, timedelta(days=1)) pipe.execute() else: with redis_client.pipeline() as pipe: self.max_active_requests = int(redis_client.get(self.max_active_requests_key).decode("utf-8")) redis_client.expire(self.max_active_requests_key, timedelta(days=1))` The code first checks whether self.max_active_requests_key exists in Redis. If it does, it proceeds to read it. However, I encountered an intermittent bug. When checking for the existence of self.max_active_requests_key in Redis, it was indeed present. But by the time I attempted to read it from Redis, the key had expired. As a result, redis_client.get(self.max_active_requests_key) returned none. ### ✔️ Expected Behavior The process of checking for the existence of a key in Redis and then reading the key from Redis should be an atomic operation. ### ❌ Actual Behavior The process of checking for the existence of a key in Redis and then reading the key from Redis is not an atomic operation.
yindo added the 🐞 bug label 2026-02-21 18:58:00 -05:00
yindo closed this issue 2026-02-21 18:58:00 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#11297