fix: 修复健康检查的两个关键bug

1. 修复双重计数usage的问题:
   - 移除 _checkProviderHealth 中的 markProviderHealthy 调用
   - 使用量计数现在只由调用方处理

2. 修复热重载timer时的竞态条件:
   - reload时重置 isHealthCheckRunning 标志
   - 避免reload期间运行时导致新timer被跳过
This commit is contained in:
Wenaixi 2026-03-31 11:54:27 +08:00
parent 642c498544
commit 9f45e77448
2 changed files with 6 additions and 2 deletions

View file

@ -1950,8 +1950,8 @@ export class ProviderPoolManager {
await serviceAdapter.generateContent(modelName, requestWithSignal);
clearTimeout(timeoutId);
// 将健康检查计入使用量resetUsageCount=false 只会递增,不会重置
this.markProviderHealthy(providerType, providerConfig, false, modelName);
// 注意使用量计数由调用方处理performScheduledHealthChecks/performHealthChecks
// 这里只返回成功结果,让调用方统一处理状态更新和计数
return { success: true, modelName, errorMessage: null };
} catch (error) {
clearTimeout(timeoutId);

View file

@ -394,6 +394,10 @@ async function startServer() {
if (healthCheckTimerId) {
clearInterval(healthCheckTimerId);
}
// 重置运行状态,允许新的 timer 立即触发
// 否则如果 reload 时正在运行,新 timer 的第一次触发会被跳过
isHealthCheckRunning = false;
// 设置定时任务
healthCheckTimerId = setInterval(async () => {
if (isHealthCheckRunning) {