mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 09:38:02 +00:00
Merge pull request #314 from sczheng189/feat/5xx-error-circuit-breaker
feat: 改进5xx错误熔断机制和重置状态功能
This commit is contained in:
@@ -1769,6 +1769,9 @@ class ClaudeAccountService {
|
||||
delete updatedAccountData.rateLimitedAt
|
||||
delete updatedAccountData.rateLimitStatus
|
||||
delete updatedAccountData.rateLimitEndAt
|
||||
delete updatedAccountData.tempErrorAt
|
||||
delete updatedAccountData.sessionWindowStart
|
||||
delete updatedAccountData.sessionWindowEnd
|
||||
|
||||
// 保存更新后的账户数据
|
||||
await redis.setClaudeAccount(accountId, updatedAccountData)
|
||||
@@ -1781,6 +1784,10 @@ class ClaudeAccountService {
|
||||
const rateLimitKey = `ratelimit:${accountId}`
|
||||
await redis.client.del(rateLimitKey)
|
||||
|
||||
// 清除5xx错误计数
|
||||
const serverErrorKey = `claude_account:${accountId}:5xx_errors`
|
||||
await redis.client.del(serverErrorKey)
|
||||
|
||||
logger.info(
|
||||
`✅ Successfully reset all error states for account ${accountData.name} (${accountId})`
|
||||
)
|
||||
@@ -1805,7 +1812,7 @@ class ClaudeAccountService {
|
||||
try {
|
||||
const accounts = await redis.getAllClaudeAccounts()
|
||||
let cleanedCount = 0
|
||||
const TEMP_ERROR_RECOVERY_MINUTES = 60 // 临时错误状态恢复时间(分钟)
|
||||
const TEMP_ERROR_RECOVERY_MINUTES = 5 // 临时错误状态恢复时间(分钟)
|
||||
|
||||
for (const account of accounts) {
|
||||
if (account.status === 'temp_error' && account.tempErrorAt) {
|
||||
|
||||
@@ -207,7 +207,7 @@ class ClaudeRelayService {
|
||||
logger.info(
|
||||
`🔥 Account ${accountId} has ${errorCount} consecutive 5xx errors in the last 5 minutes`
|
||||
)
|
||||
if (errorCount >= 3) {
|
||||
if (errorCount > 10) {
|
||||
logger.error(
|
||||
`❌ Account ${accountId} exceeded 5xx error threshold (${errorCount} errors), marking as temp_error`
|
||||
)
|
||||
@@ -939,7 +939,7 @@ class ClaudeRelayService {
|
||||
logger.info(
|
||||
`🔥 [Stream] Account ${accountId} has ${errorCount} consecutive 5xx errors in the last 5 minutes`
|
||||
)
|
||||
if (errorCount >= 3) {
|
||||
if (errorCount > 10) {
|
||||
logger.error(
|
||||
`❌ [Stream] Account ${accountId} exceeded 5xx error threshold (${errorCount} errors), marking as temp_error`
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user