mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 00:53:33 +00:00
fix: 优化 API Key 并发控制机制
- 调整并发计数器过期时间为3分钟,支持长时间流式请求 - 为流式响应添加客户端断开检测,确保计数正确减少 - 添加响应关闭和错误事件监听器,防止并发计数泄漏 - 提高系统稳定性和资源管理准确性 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -721,8 +721,10 @@ class RedisClient {
|
||||
const key = `concurrency:${apiKeyId}`;
|
||||
const count = await this.client.incr(key);
|
||||
|
||||
// 设置过期时间为5分钟,防止计数器永远不清零
|
||||
await this.client.expire(key, 300);
|
||||
// 设置过期时间为180秒(3分钟),防止计数器永远不清零
|
||||
// 正常情况下请求会在完成时主动减少计数,这只是一个安全保障
|
||||
// 180秒足够支持较长的流式请求
|
||||
await this.client.expire(key, 180);
|
||||
|
||||
logger.database(`🔢 Incremented concurrency for key ${apiKeyId}: ${count}`);
|
||||
return count;
|
||||
|
||||
Reference in New Issue
Block a user