Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

Fix: RateLimit requests were not released when a streaming generation exception occurred (#11540)

liuzhenghuad05f1890497e
diff --git a/api/core/app/features/rate_limiting/rate_limit.py b/api/core/app/features/rate_limiting/rate_limit.py
index 154a49ebda2..8fe1d96b37b 100644
--- a/api/core/app/features/rate_limiting/rate_limit.py
+++ b/api/core/app/features/rate_limiting/rate_limit.py
@@ -110,7 +110,7 @@ class RateLimitGenerator:
raise StopIteration
try:
return next(self.generator)
- except StopIteration:
+ except Exception:
self.close()
raise
diff --git a/api/services/app_generate_service.py b/api/services/app_generate_service.py
index 545de8190cb..9def7d15e92 100644
--- a/api/services/app_generate_service.py
+++ b/api/services/app_generate_service.py
@@ -108,6 +108,9 @@ class AppGenerateService:
raise ValueError(f"Invalid app mode {app_model.mode}")
except RateLimitError as e:
raise InvokeRateLimitError(str(e))
+ except Exception:
+ rate_limit.exit(request_id)
+ raise
finally:
if not streaming:
rate_limit.exit(request_id)