fix: 修复服务启动时的竞态条件,等待健康检查通过后再报告就绪

This commit is contained in:
2026-03-20 14:12:00 +08:00
parent 9effdcd070
commit 8ee86c7b0f
4 changed files with 62 additions and 10 deletions

View File

@@ -113,14 +113,21 @@ class OpenCodeService {
this.process = null;
});
await new Promise<void>((resolve) => {
setTimeout(resolve, 2000);
});
const maxWaitTime = 30000;
const checkInterval = 500;
const startTime = Date.now();
const isHealthy = await this.checkHealth();
if (!isHealthy) {
log.warn('[OpenCodeService] Server started but health check failed, waiting longer...');
await new Promise<void>((resolve) => setTimeout(resolve, 3000));
while (Date.now() - startTime < maxWaitTime) {
const isHealthy = await this.checkHealth();
if (isHealthy) {
break;
}
await new Promise<void>((resolve) => setTimeout(resolve, checkInterval));
}
const finalHealth = await this.checkHealth();
if (!finalHealth) {
log.warn('[OpenCodeService] Health check failed after max wait time');
}
this._isRunning = true;

View File

@@ -125,7 +125,22 @@ class SDDService {
this.processPid = null;
});
await new Promise<void>((resolve) => setTimeout(resolve, 2000));
const maxWaitTime = 30000;
const checkInterval = 500;
const startTime = Date.now();
while (Date.now() - startTime < maxWaitTime) {
const isHealthy = await this.checkHealth();
if (isHealthy) {
break;
}
await new Promise<void>((resolve) => setTimeout(resolve, checkInterval));
}
const finalHealth = await this.checkHealth();
if (!finalHealth) {
log.warn('[SDDService] Health check failed after max wait time');
}
this._isRunning = true;
this._isStarting = false;

View File

@@ -125,7 +125,22 @@ class TerminalService {
this.processPid = null;
});
await new Promise<void>((resolve) => setTimeout(resolve, 2000));
const maxWaitTime = 30000;
const checkInterval = 500;
const startTime = Date.now();
while (Date.now() - startTime < maxWaitTime) {
const isHealthy = await this.checkHealth();
if (isHealthy) {
break;
}
await new Promise<void>((resolve) => setTimeout(resolve, checkInterval));
}
const finalHealth = await this.checkHealth();
if (!finalHealth) {
log.warn('[TerminalService] Health check failed after max wait time');
}
this._isRunning = true;
this._isStarting = false;

View File

@@ -125,7 +125,22 @@ class XCOpenCodeWebService {
this.processPid = null;
});
await new Promise<void>((resolve) => setTimeout(resolve, 2000));
const maxWaitTime = 30000;
const checkInterval = 500;
const startTime = Date.now();
while (Date.now() - startTime < maxWaitTime) {
const isHealthy = await this.checkHealth();
if (isHealthy) {
break;
}
await new Promise<void>((resolve) => setTimeout(resolve, checkInterval));
}
const finalHealth = await this.checkHealth();
if (!finalHealth) {
log.warn('[XCOpenCodeWebService] Health check failed after max wait time');
}
this._isRunning = true;
this._isStarting = false;