fix: 修复服务启动时的竞态条件,等待健康检查通过后再报告就绪
This commit is contained in:
@@ -113,14 +113,21 @@ class OpenCodeService {
|
|||||||
this.process = null;
|
this.process = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
await new Promise<void>((resolve) => {
|
const maxWaitTime = 30000;
|
||||||
setTimeout(resolve, 2000);
|
const checkInterval = 500;
|
||||||
});
|
const startTime = Date.now();
|
||||||
|
|
||||||
const isHealthy = await this.checkHealth();
|
while (Date.now() - startTime < maxWaitTime) {
|
||||||
if (!isHealthy) {
|
const isHealthy = await this.checkHealth();
|
||||||
log.warn('[OpenCodeService] Server started but health check failed, waiting longer...');
|
if (isHealthy) {
|
||||||
await new Promise<void>((resolve) => setTimeout(resolve, 3000));
|
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;
|
this._isRunning = true;
|
||||||
|
|||||||
@@ -125,7 +125,22 @@ class SDDService {
|
|||||||
this.processPid = null;
|
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._isRunning = true;
|
||||||
this._isStarting = false;
|
this._isStarting = false;
|
||||||
|
|||||||
@@ -125,7 +125,22 @@ class TerminalService {
|
|||||||
this.processPid = null;
|
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._isRunning = true;
|
||||||
this._isStarting = false;
|
this._isStarting = false;
|
||||||
|
|||||||
@@ -125,7 +125,22 @@ class XCOpenCodeWebService {
|
|||||||
this.processPid = null;
|
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._isRunning = true;
|
||||||
this._isStarting = false;
|
this._isStarting = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user