{"record":{"id":"806822f443537509","repo":"abhigyanpatwari/GitNexus","slug":"ladybugdb-unavailable-for-repoid-another-proce","errorCode":null,"errorMessage":"LadybugDB unavailable for ${repoId}. Another process may be rebuilding the index. Retry later. (${lastError?.message || 'unknown error'})","messagePattern":"LadybugDB unavailable for (.+?)\\. Another process may be rebuilding the index\\. Retry later\\. \\((.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gitnexus/src/core/lbug/pool-adapter.ts","lineNumber":794,"sourceCode":"        if (\n          lastError.message.startsWith('LadybugDB checkpoint sidecar is missing') ||\n          lastError.message.startsWith('LadybugDB checkpoint sidecar is present but unreachable') ||\n          lastError.message.startsWith('GitNexus could not move the LadybugDB WAL sidecar') ||\n          isMissingShadowSidecarError(lastError)\n        ) {\n          throw lastError;\n        }\n\n        const isLockError =\n          lastError.message.includes('Could not set lock') ||\n          /\\block(\\b|ed|ing)/i.test(lastError.message);\n        if (!isLockError || attempt === LOCK_RETRY_ATTEMPTS) break;\n        await new Promise((resolve) => setTimeout(resolve, LOCK_RETRY_DELAY_MS * attempt));\n      }\n    }\n\n    if (!shared) {\n      throw new Error(\n        `LadybugDB unavailable for ${repoId}. Another process may be rebuilding the index. ` +\n          `Retry later. (${lastError?.message || 'unknown error'})`,\n      );\n    }\n  }\n\n  shared.refCount++;\n  const db = shared.db;\n\n  // Pre-create the full pool upfront so createConnection() (which silences\n  // stdout) is never called lazily during active query execution.\n  // Mark preWarmActive so the watchdog timer doesn't interfere.\n  preWarmActive = true;\n  const available: lbug.Connection[] = [];\n  try {\n    for (let i = 0; i < MAX_CONNS_PER_REPO; i++) {\n      available.push(createConnection(db));\n    }","sourceCodeStart":776,"sourceCodeEnd":812,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/d540b00184d71a896261ee02670da9a92d59d8f7/gitnexus/src/core/lbug/pool-adapter.ts#L776-L812","documentation":"Thrown by doInitLbug after all lock-retry attempts are exhausted without successfully opening the database. The retry loop (LOCK_RETRY_ATTEMPTS=3, LOCK_RETRY_DELAY_MS=2000 with linear back-off) handles transient lock contention where another process briefly holds the DB lock; if all 3 attempts fail, the DB is genuinely locked by another process or the lock file is stale. The error includes the lastError message for diagnostics and advises retrying later.","triggerScenarios":"Calling initLbug for a repoId while another process (typically `gitnexus analyze` or another `gitnexus serve` instance) holds an exclusive lock on the LadybugDB database file; all 3 retry attempts (at 2s, 4s, 6s) encounter the lock error ('Could not set lock' or matching /lock(b|ed|ing)/i). The loop also breaks early on non-lock errors that aren't retryable.","commonSituations":"Running `gitnexus serve` while `gitnexus analyze` is rebuilding the same repo's index; two MCP server instances pointing at the same repository; an analyze that crashed and left a stale lock file; a long-running analyze on a large repo that holds the lock for minutes.","solutions":["Wait for the other GitNexus process to finish (check with `ps aux | grep gitnexus`), then retry","If no process is running but the lock persists (stale lock), delete the .lock file in the .gitnexus/ storage directory and retry","Run `gitnexus analyze --force` which acquires its own lock and will clear stale lock state","Ensure only one GitNexus process accesses a given repository at a time — the pool adapter is read-only and cannot share with a concurrent writer"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Check if another process holds the DB lock before initializing\nimport { access } from 'fs/promises';\n// Best pre-check: look for running gitnexus processes\nimport { execSync } from 'child_process';\nfunction gitnexusProcessesRunning(): boolean {\n  try {\n    const out = execSync('pgrep -f gitnexus', { encoding: 'utf8' });\n    return out.trim().length > 0;\n  } catch {\n    return false;\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await doInitLbug(repoId, dbPath);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('LadybugDB unavailable')) {\n    // Wait for the other process to finish, or stop it manually\n    logger.warn('DB locked by another process — wait or stop it, then retry');\n    // Optionally: await sleep(10000); await doInitLbug(repoId, dbPath);\n  }\n  throw e;\n}","preventionTips":["Ensure only one GitNexus process accesses a given repository at a time","Stop `gitnexus serve` before running `gitnexus analyze`","If no process is running but the lock persists, delete the .lock file manually","In shared/CI environments, use file-based locking or job queues to serialize access"],"tags":["ladybugdb","lock-contention","pool-adapter","concurrent-access","retry-exhausted"],"backgroundTag":null,"analyzedSha":"d540b00184d71a896261ee02670da9a92d59d8f7","analyzedAt":"2026-08-12T19:50:25.132Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}