{"record":{"id":"68edf3d9cb90ebf4","repo":"thedotmack/claude-mem","slug":"worker-shutdown-attempt-failed-error-instanceof","errorCode":null,"errorMessage":"Worker shutdown attempt failed: ${error instanceof Error ? error.message : String(error)}","messagePattern":"Worker shutdown attempt failed: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/npx-cli/commands/uninstall.ts","lineNumber":280,"sourceCode":"      initialValue: false,\n    });\n\n    if (p.isCancel(shouldContinue) || !shouldContinue) {\n      p.cancel('Uninstall cancelled.');\n      return;\n    }\n  }\n\n  const workerPort = SettingsDefaultsManager.get('CLAUDE_MEM_WORKER_PORT');\n  try {\n    const result = await shutdownWorkerAndWait(workerPort, 10000);\n    if (result.workerWasRunning && result.stopped) {\n      p.log.info('Worker service stopped.');\n    } else if (result.workerWasRunning) {\n      p.log.warn('Worker service did not confirm shutdown; continuing uninstall cleanup.');\n    }\n  } catch (error: unknown) {\n    console.warn('[uninstall] Worker shutdown attempt failed:', error instanceof Error ? error.message : String(error));\n  }\n\n  // #2568 — server-runtime teardown. Gated on the installed/selected runtime so\n  // the worker uninstall path is completely unchanged. The bundled Docker\n  // compose stack lives under the marketplace dir; if it's present we treat the\n  // stack as locally managed and instruct teardown (the actual `docker compose\n  // down -v` is an operator/CI side effect, not run from this Node process).\n  const selectedRuntime = readSelectedRuntime();\n  if (selectedRuntime === 'server') {\n    if (existsSync(join(marketplaceDirectory(), 'docker-compose.yml'))) {\n      p.log.info(\n        'Server runtime detected. Tear down the bundled stack with '\n          + '`docker compose down -v --remove-orphans` (stops + removes pg + redis/valkey).',\n      );\n    } else {\n      p.log.info('Server runtime detected (externally managed stack — leaving Docker/pg/redis untouched).');\n    }\n    clearServerRuntimeSettings(SERVER_RUNTIME_SETTINGS_KEYS);","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/8bc631a71a487424b866756e43a6efa4574cc66b/src/npx-cli/commands/uninstall.ts#L262-L298","documentation":"During `npx claude-mem uninstall`, the command attempts to stop the running worker service before cleanup. If the shutdown call itself throws (as opposed to merely reporting it did not stop), the error is caught and logged to console.warn as '[uninstall] Worker shutdown attempt failed: <message>', and uninstall continues. Unlike install, this is non-fatal by design: cleanup proceeds even if shutdown could not be attempted.","triggerScenarios":"runUninstallCommand calls shutdownWorkerAndWait(workerPort, 10000) and that call throws — e.g. an invalid CLAUDE_MEM_WORKER_PORT setting, a network error contacting the worker, or an unexpected exception inside the shutdown helper.","commonSituations":"Worker already crashed leaving a half-open socket; CLAUDE_MEM_WORKER_PORT setting missing or invalid; the 10s timeout window expiring and the helper throwing instead of returning stopped:false; OS-level restrictions on signalling the worker process.","solutions":["Ignore it if uninstall completed — cleanup continues by design; verify no worker process remains afterward.","Run `npx claude-mem stop` or manually kill the worker process after uninstall.","Check CLAUDE_MEM_WORKER_PORT is a valid port number in settings.","Re-run uninstall to confirm the worker is no longer running."],"exampleFix":"// before\nnpx claude-mem uninstall   // warns: Worker shutdown attempt failed: ...\n// after\nps aux | grep claude-mem   # confirm/kill leftover worker\nnpx claude-mem uninstall","handlingStrategy":"try-catch","validationCode":"const port = Number(settings.CLAUDE_MEM_WORKER_PORT);\nif (!Number.isInteger(port) || port <= 0 || port > 65535) console.warn('invalid worker port; fix settings before uninstall');","typeGuard":null,"tryCatchPattern":"try {\n  await shutdownWorkerAndWait(workerPort, 10000);\n} catch (error) {\n  console.warn('[uninstall] Worker shutdown attempt failed:', error instanceof Error ? error.message : String(error));\n  // continue cleanup; verify no leftover worker afterward\n}","preventionTips":["Ensure CLAUDE_MEM_WORKER_PORT is set to a valid port before running uninstall.","Check for a live worker (health endpoint) before uninstall and stop it gracefully.","Treat the warning as a signal to manually verify/kill leftover worker processes.","Re-run uninstall to confirm a clean state."],"tags":["worker","shutdown","uninstall","process-lifecycle"],"backgroundTag":"connection-refused","analyzedSha":"8bc631a71a487424b866756e43a6efa4574cc66b","analyzedAt":"2026-09-09T10:47:06.009Z","contentChangedAt":"2026-09-09T10:47:06.009Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}