{"record":{"id":"0f772edb4fe8db84","repo":"mihomo-party-org/clash-party","slug":"core-startup-was-cancelled-because-the-application","errorCode":null,"errorMessage":"Core startup was cancelled because the application is shutting down","messagePattern":"Core startup was cancelled because the application is shutting down","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/main/core/manager.ts","lineNumber":143,"sourceCode":"export 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(\n    () => undefined,\n    () => undefined\n  )\n  return current\n}\n","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/mihomo-party-org/clash-party/blob/911e090537acdf7c50bee1c3aebecc2ef119a8b5/src/main/core/manager.ts#L125-L161","documentation":"This error is thrown by ensureCoreOperationAllowed() in src/main/core/manager.ts:143 when coreOperationPhase === 'shutting-down'. It means a core operation (startCore, stopCore, restartCore, restartCoreAfterUnexpectedExit) was requested while the application is in the middle of shutting down, so the library cancels it to avoid starting or mutating the core during teardown.","triggerScenarios":"Invoking startCore(), stopCore(), restartCore(), or restartCoreAfterUnexpectedExit() after app shutdown began and set coreOperationPhase to 'shutting-down' (via beginShutdown / quit flow), including queued operations that resolve after shutdown started.","commonSituations":"A renderer or IPC handler triggering a core restart while the user quits the app; a queued restart promise resolving during app close; OS shutdown or window close firing while a core operation was pending.","solutions":["Listen for the app's shutdown/before-quit signal and stop issuing core operations at that point","Guard core calls behind a check that the app is not shutting down (e.g. an isShuttingDown flag exposed by the app)","Treat this error as benign and swallow it in quit paths — the core is being torn down intentionally"],"exampleFix":"// before\nawait restartCore()\n// after\nif (!app.isShuttingDown) { await restartCore() } else { log.info('skip restart during shutdown') }","handlingStrategy":"try-catch","validationCode":"if (coreOperationPhase === 'shutting-down' || app.isShuttingDown) {\n  return // skip core operation entirely\n}","typeGuard":null,"tryCatchPattern":"try {\n  await restartCore()\n} catch (err) {\n  if (err.message.includes('application is shutting down')) {\n    log.info('Core restart skipped: app shutting down')\n    return\n  }\n  throw err\n}","preventionTips":["Subscribe to before-quit/shutdown events and disable core controls","Debounce queued restarts so they do not fire during teardown","Treat shutdown-phase errors as benign in quit paths"],"tags":["lifecycle","shutdown","race-condition","core-manager"],"backgroundTag":"operation-cancelled-during-shutdown","analyzedSha":"911e090537acdf7c50bee1c3aebecc2ef119a8b5","analyzedAt":"2026-08-30T13:00:49.174Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}