{"record":{"id":"a572573e28cecafb","repo":"abhigyanpatwari/GitNexus","slug":"timed-out-after-waitedms-ms-waiting-for-another","errorCode":null,"errorMessage":"Timed out after ${waitedMs}ms waiting for another gitnexus analyze (pid ${holder.pid} on ${holder.hostname}, invocation ${holder.invocationId}) to release the index lock.","messagePattern":"Timed out after (.+?)ms waiting for another gitnexus analyze \\(pid (.+?) on (.+?), invocation (.+?)\\) to release the index lock\\.","errorType":"exception","errorClass":"IndexLockTimeoutError","httpStatus":null,"severity":"error","filePath":"gitnexus/src/storage/index-lock.ts","lineNumber":693,"sourceCode":"        throw error;\n      }\n    } finally {\n      releaseAcquisitionGuard(guardPath, me, createdMain, lockPath);\n    }\n    const waited = Date.now() - startedAt;\n\n    if (holder) {\n      // Live holder → wait.\n      lastLiveHolder = holder;\n      if (!announcedWait) {\n        announcedWait = true;\n        opts.onWaitStart?.(holder);\n        opts.log?.(\n          `Another gitnexus analyze (pid ${holder.pid} on ${holder.hostname}) is ` +\n            `refreshing this index — waiting for it to finish.`,\n        );\n      }\n      if (waited >= timeoutMs) throw new IndexLockTimeoutError(holder, waited);\n      if (Date.now() - lastDiagnosticAt >= DIAGNOSTIC_INTERVAL_MS) {\n        lastDiagnosticAt = Date.now();\n        if (waited >= DIAGNOSTIC_INTERVAL_MS) {\n          opts.log?.(\n            `Still waiting for analyze pid ${holder.pid} (${Math.round(waited / 1000)}s elapsed).`,\n          );\n        }\n      }\n      await sleep(jitteredDelay(pollMs, timeoutMs, waited));\n      continue;\n    }\n\n    if (waited >= timeoutMs) throw new IndexLockTimeoutError(unknownHolder(), waited, false);\n    const waitCeiling = Math.min(\n      timeoutMs,\n      permissionWaitSince === null\n        ? Number.POSITIVE_INFINITY\n        : permissionWaitSince + GUARD_TIMEOUT_MS - startedAt,","sourceCodeStart":675,"sourceCodeEnd":711,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/ac9a4e9abd8fd3058c070b72c23402a4f887929a/gitnexus/src/storage/index-lock.ts#L675-L711","documentation":"gitnexus analyze serializes index writes with a per-index lock. The file backend reads the holder record (pid, hostname, invocationId) and waits, announcing the other run; if the live holder does not release within the wait ceiling (default 600,000 ms from DEFAULT_TIMEOUT_MS; override via AcquireOptions.timeoutMs or GITNEXUS_INDEX_LOCK_TIMEOUT_MS, ≤0 for unbounded), acquisition fails with IndexLockTimeoutError naming the holder.","triggerScenarios":"Two `gitnexus analyze` runs on the same repo overlap — e.g. a scheduled CI refresh still running while a developer or IDE/MCP-triggered analyze starts — and the holder's run exceeds the timeout (10 minutes by default).","commonSituations":"CI cron overlapping manual runs; very large repos whose reindex legitimately runs past 10 minutes; shared/mounted storage where another host's analyze holds the lock.","solutions":["Identify the named holder (pid on hostname) with ps, let it finish or kill it if wedged, then retry analyze","Serialize analyze runs at the orchestration layer (CI mutex/queue, single scheduler) so only one runs per repo","Raise the ceiling for very large repos: GITNEXUS_INDEX_LOCK_TIMEOUT_MS=3600000","Confirm both runs targeting the same index is intended — if not, point one at a different repo/storage path"],"exampleFix":"# before — times out at the 10-minute default on a huge repo\n gitnexus analyze .\n\n# after\nGITNEXUS_INDEX_LOCK_TIMEOUT_MS=3600000 gitnexus analyze .","handlingStrategy":"retry","validationCode":"import { execSync } from 'node:child_process';\nfunction otherAnalyzeRunning(): boolean {\n  try {\n    const out = execSync('pgrep -af \"gitnexus analyze\" || true', { encoding: 'utf8' });\n    return out\n      .split('\\n')\n      .some((l) => l.trim() && !l.startsWith(String(process.pid)));\n  } catch {\n    return false;\n  }\n}\nif (otherAnalyzeRunning()) await waitForOtherAnalyze();","typeGuard":null,"tryCatchPattern":"try {\n  await runAnalyze();\n} catch (e) {\n  if (e?.name === 'IndexLockTimeoutError' && e.holder?.pid) {\n    console.warn(`holder pid ${e.holder.pid} on ${e.holder.hostname} — retrying once after it exits`);\n    await sleep(60_000);\n    return runAnalyze(); // one bounded retry, not a loop\n  }\n  throw e;\n}","preventionTips":["Serialize analyze runs per repo with an orchestration-level mutex or CI queue","Set GITNEXUS_INDEX_LOCK_TIMEOUT_MS above your worst-case reindex duration on big repos","Check the holder pid with ps before killing anything — a live long reindex is healthy, not stuck"],"tags":["concurrency","file-lock","indexing","timeout"],"backgroundTag":"lock-acquisition-timeout","analyzedSha":"ac9a4e9abd8fd3058c070b72c23402a4f887929a","analyzedAt":"2026-08-20T23:29:22.980Z","contentChangedAt":"2026-08-20T23:29:22.980Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}