Stop launching extra Comfy Pythons when the running instance is just busy.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -52,15 +52,16 @@ export async function checkComfyHttp(timeoutMs = 5000, host?: string) {
|
||||
let resolved = host || ''
|
||||
try {
|
||||
if (!resolved) {
|
||||
if (!comfyConfigured()) return { ok: false as const, host: '', status: 0, stats: null }
|
||||
if (!comfyConfigured()) return { ok: false as const, host: '', status: 0, stats: null, timedOut: false }
|
||||
resolved = getComfyHost()
|
||||
}
|
||||
const res = await fetch(`${resolved}/system_stats`, { signal: AbortSignal.timeout(timeoutMs) })
|
||||
if (!res.ok) return { ok: false as const, host: resolved, status: res.status, stats: null }
|
||||
if (!res.ok) return { ok: false as const, host: resolved, status: res.status, stats: null, timedOut: false }
|
||||
const stats = await res.json().catch(() => null)
|
||||
return { ok: true as const, host: resolved, status: res.status, stats }
|
||||
} catch {
|
||||
return { ok: false as const, host: resolved, status: 0, stats: null }
|
||||
return { ok: true as const, host: resolved, status: res.status, stats, timedOut: false }
|
||||
} catch (error) {
|
||||
const timedOut = error instanceof Error && (error.name === 'TimeoutError' || error.name === 'AbortError' || /timeout/i.test(error.message))
|
||||
return { ok: false as const, host: resolved, status: 0, stats: null, timedOut }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,6 +349,24 @@ async function ensureUnlocked(onStatus: StatusFn, skipBusyWait = false) {
|
||||
onStatus({ state: 'online', message: 'ComfyUI online', host })
|
||||
return
|
||||
}
|
||||
if (health.timedOut) {
|
||||
log('http-busy', { host, timeoutMs: cfg.healthTimeoutMs })
|
||||
const retry = await checkComfyHttp(Math.max(cfg.healthTimeoutMs, 12_000))
|
||||
if (retry.ok) {
|
||||
if (!skipBusyWait) await waitWhileBusy(onStatus)
|
||||
onStatus({ state: 'online', message: 'ComfyUI online', host })
|
||||
return
|
||||
}
|
||||
onStatus({
|
||||
state: 'busy',
|
||||
message: 'ComfyUI is loaded but slow to answer. Not starting another instance.',
|
||||
host,
|
||||
processRunning: true
|
||||
})
|
||||
if (!skipBusyWait) await waitWhileBusy(onStatus)
|
||||
onStatus({ state: 'online', message: 'ComfyUI online', host, processRunning: true })
|
||||
return
|
||||
}
|
||||
|
||||
log('http-fail', { host })
|
||||
const remote = await controlRequest('/status')
|
||||
@@ -383,11 +402,9 @@ async function ensureUnlocked(onStatus: StatusFn, skipBusyWait = false) {
|
||||
onStatus({ state: 'online', message: 'ComfyUI online', host, processRunning: true })
|
||||
return
|
||||
}
|
||||
onStatus({
|
||||
state: 'starting',
|
||||
message: 'ComfyUI is running but the API never came up. Attempting a relaunch...',
|
||||
host,
|
||||
processRunning: true
|
||||
throw createError({
|
||||
statusCode: 503,
|
||||
statusMessage: 'ComfyUI is running but the API never came up. Not launching a second instance.'
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user