{"record":{"id":"e51d63f56b3317a8","repo":"thedotmack/claude-mem","slug":"request-timed-out-after-timeoutms-ms","errorCode":null,"errorMessage":"Request timed out after ${timeoutMs}ms","messagePattern":"Request timed out after (.+?)ms","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/shared/worker-utils.ts","lineNumber":156,"sourceCode":"  } catch (err: unknown) {\n    if (isWorkerFetchVerboseEnabled()) {\n      logVerboseFetchFailure(url, init, err);\n    }\n    throw err;\n  }\n}\n\nexport async function fetchWithTimeout(url: string, init: RequestInit = {}, timeoutMs: number): Promise<Response> {\n  try {\n    // AbortSignal.timeout (Node 18+) replaces the manual setTimeout/clearTimeout\n    // race. On expiry it aborts with a TimeoutError DOMException.\n    return await workerFetch(url, { ...init, signal: AbortSignal.timeout(timeoutMs) });\n  } catch (err: unknown) {\n    // Preserve the historical timeout-error message (\"...timed out...\") that\n    // callers match on (hook-command.ts, server-beta-client.ts) — the\n    // DOMException text is runtime-dependent, so normalize it here.\n    if (err instanceof DOMException && err.name === 'TimeoutError') {\n      throw new Error(`Request timed out after ${timeoutMs}ms`);\n    }\n    throw err;\n  }\n}\n\nlet cachedPort: number | null = null;\nlet cachedHost: string | null = null;\nlet cachedSettings: SettingsDefaults | null = null;\nlet cachedApiRequestTimeoutMs: number | null = null;\n\nfunction getWorkerSettingsPath(): string {\n  return path.join(SettingsDefaultsManager.get('CLAUDE_MEM_DATA_DIR'), 'settings.json');\n}\n\nfunction getWorkerSettings(): SettingsDefaults {\n  if (cachedSettings !== null) {\n    return cachedSettings;\n  }","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/shared/worker-utils.ts#L138-L174","documentation":"fetchWithTimeout wraps workerFetch with AbortSignal.timeout(timeoutMs). When the fetch aborts with a DOMException named 'TimeoutError', the DOMException (whose text is runtime-dependent) is normalized into the stable message 'Request timed out after <N>ms' so callers like hook-command.ts and server-beta-client.ts can match on the text reliably.","triggerScenarios":"workerHttpRequest -> fetchWithTimeout with a timeoutMs deadline, and the worker HTTP request does not complete before AbortSignal.timeout fires: the worker process is hung, slow, or not draining its HTTP handler.","commonSituations":"claude-mem worker busy or deadlocked so requests queue; very short timeoutMs for a heavy hook request; machine under load or the Chroma service the worker proxies to is slow.","solutions":["Check the worker is alive and responsive (`claude-mem status` / worker logs); restart it if hung","Increase the timeoutMs passed to fetchWithTimeout/workerHttpRequest for heavy requests","Add retry-with-backoff around the call for transient slowness, and match the stable 'Request timed out after' message in catch blocks"],"exampleFix":"// before\nconst res = await workerHttpRequest('/hooks', init, 1000); // too tight\n\n// after\nconst res = await withRetry(() => workerHttpRequest('/hooks', init, 10000), { retries: 2 });\n// catch (e) { if (e.message.includes('Request timed out after')) ... }","handlingStrategy":"retry","validationCode":"null","typeGuard":"function isTimeoutError(e: unknown): boolean {\n  return e instanceof Error && e.message.includes('Request timed out after');\n}","tryCatchPattern":"try {\n  return await fetchWithTimeout(url, init, timeoutMs);\n} catch (e) {\n  if (isTimeoutError(e)) {\n    await sleep(backoffMs);\n    return await fetchWithTimeout(url, init, timeoutMs * 2); // retry once with a larger budget\n  }\n  throw e;\n}","preventionTips":["Set timeoutMs generously relative to the heaviest expected worker request","Monitor worker health/restart it when requests start timing out","Match on the stable 'Request timed out after' message rather than DOMException text"],"tags":["http","timeout","worker"],"backgroundTag":"request-timeout","analyzedSha":"d8bc9755e74915e5c3b999181e10a67c889bce2a","analyzedAt":"2026-09-17T16:40:26.182Z","contentChangedAt":"2026-09-17T16:40:26.182Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}