Stop launching extra Comfy Pythons when the running instance is just busy.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Towsty
2026-09-02 22:35:27 -05:00
co-authored by Cursor
parent eccf8c0081
commit c79cca39ae
3 changed files with 65 additions and 18 deletions
+19 -6
View File
@@ -55,16 +55,17 @@ export async function checkImageComfyHttp(timeoutMs = 5000, host?: string) {
let resolved = host || ''
try {
if (!resolved) {
if (!imageComfyConfigured()) return { ok: false as const, host: '', status: 0, stats: null }
if (!imageComfyConfigured()) return { ok: false as const, host: '', status: 0, stats: null, timedOut: false }
resolved = getImageComfyHost()
}
if (!resolved) return { ok: false as const, host: '', status: 0, stats: null }
if (!resolved) return { ok: false as const, host: '', status: 0, stats: null, timedOut: false }
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 }
}
}
@@ -173,6 +174,18 @@ async function ensureUnlocked(onStatus: StatusFn) {
onStatus({ state: 'online', message: 'Image ComfyUI online', host })
return
}
if (health.timedOut) {
log('http-busy', { host, timeoutMs: cfg.healthTimeoutMs })
onStatus({
state: 'busy',
message: 'Image ComfyUI is loaded but slow to answer. Not starting another instance.',
host,
processRunning: true
})
await waitWhileBusy(onStatus)
onStatus({ state: 'online', message: 'Image ComfyUI online', host, processRunning: true })
return
}
const remote = await controlRequest('/status')
if (remote?.http && remote.proxyPort) {