{"record":{"id":"491cfec164e3cf8d","repo":"mihomo-party-org/clash-party","slug":"core-is-still-initializing","errorCode":null,"errorMessage":"Core is still initializing","messagePattern":"Core is still initializing","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/main/core/manager.ts","lineNumber":137,"sourceCode":"}\n\nexport function hasCoreProcess(): boolean {\n  return Boolean(child && !child.killed && child.exitCode === null && child.signalCode === null)\n}\n\nexport function beginCoreInitialization(): void {\n  coreOperationPhase = 'initializing'\n}\n\nexport function completeCoreInitialization(canStart: boolean): void {\n  if (coreOperationPhase !== 'shutting-down') {\n    coreOperationPhase = canStart ? 'ready' : 'blocked'\n  }\n}\n\nfunction ensureCoreOperationAllowed(): void {\n  if (coreOperationPhase === 'initializing') {\n    throw new Error('Core is still initializing')\n  }\n  if (coreOperationPhase === 'blocked') {\n    throw new Error('Core startup is unavailable because startup safety checks did not pass')\n  }\n  if (coreOperationPhase === 'shutting-down') {\n    throw new Error('Core startup was cancelled because the application is shutting down')\n  }\n}\n\nfunction ensureNotShuttingDown(): void {\n  if (coreOperationPhase === 'shutting-down') {\n    throw new Error('Core startup was cancelled because the application is shutting down')\n  }\n}\n\nfunction runCoreOperation<T>(operation: () => Promise<T>): Promise<T> {\n  const current = coreOperationTail.then(operation, operation)\n  coreOperationTail = current.then(","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/mihomo-party-org/clash-party/blob/911e090537acdf7c50bee1c3aebecc2ef119a8b5/src/main/core/manager.ts#L119-L155","documentation":"ensureCoreOperationAllowed gates core lifecycle operations (startCore, stopCore, restartCore, restartCoreAfterUnexpectedExit) against a module-level coreOperationPhase state machine. If the phase is 'initializing' (startup safety checks still running), it throws 'Core is still initializing' to prevent concurrent/lifecycle races.","triggerScenarios":"Calling startCore/stopCore/restartCore (directly or via IPC) while the app is still in the 'initializing' phase — i.e. before startup safety checks complete and set the phase to 'ready' or 'blocked'.","commonSituations":"Renderer fires start/restart immediately on app launch before initialization finishes; automation scripts driving IPC faster than startup; a restart requested during the startup window after an unexpected core exit.","solutions":["Wait for core initialization to complete before invoking core operations (listen for the app's ready/initialized signal).","Retry the operation after a short delay if it must be issued around startup.","Guard IPC handlers on the renderer side to disable core controls during the initializing phase.","If initialization seems stuck, check startup safety check logs for why the phase never reaches 'ready'."],"exampleFix":"// before\nonAppReady(() => restartCore()) // may run during 'initializing'\n// after\nwhenCoreInitialized(async () => {\n  try { await restartCore() }\n  catch (e) {\n    if (e.message === 'Core is still initializing') await retryWithDelay(restartCore)\n  }\n})","handlingStrategy":"retry","validationCode":"// on the renderer side, gate calls on app readiness\nif (!coreReady) {\n  await waitForCoreReadySignal() // e.g. IPC event 'core:ready'\n}\nawait restartCore()","typeGuard":null,"tryCatchPattern":"async function safeRestart() {\n  try {\n    await restartCore()\n  } catch (e) {\n    if (e.message === 'Core is still initializing') {\n      await new Promise((r) => setTimeout(r, 1000))\n      return safeRestart() // or use the core:ready event\n    }\n    throw e\n  }\n}","preventionTips":["Wait for the app's initialization/ready event before issuing core operations.","Disable core control buttons in the UI during the initializing phase.","Prefer event-driven startup over fixed setTimeout delays where possible.","Check startup safety-check logs if the initializing phase never completes."],"tags":["lifecycle","concurrency","state-machine","core"],"backgroundTag":"operation-blocked-during-initialization","analyzedSha":"911e090537acdf7c50bee1c3aebecc2ef119a8b5","analyzedAt":"2026-08-30T13:00:49.174Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}