{"record":{"id":"2ebadd1483e34531","repo":"abhigyanpatwari/GitNexus","slug":"connection-pool-integrity-error-expected-max-co","errorCode":null,"errorMessage":"Connection pool integrity error: expected ${MAX_CONNS_PER_REPO} connections but found ${totalConns} (${entry.available.length} available, ${entry.checkedOut} checked out)","messagePattern":"Connection pool integrity error: expected (.+?) connections but found (.+?) \\((.+?) available, (.+?) checked out\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gitnexus/src/core/lbug/pool-adapter.ts","lineNumber":1165,"sourceCode":"\n/**\n * Checkout a connection from the pool.\n * Returns an available connection, or creates a new one if under the cap.\n * If all connections are busy and at cap, queues the caller until one is returned.\n */\nfunction checkout(entry: PoolEntry): Promise<lbug.Connection> {\n  // Fast path: grab an available connection\n  if (entry.available.length > 0) {\n    entry.checkedOut++;\n    return Promise.resolve(entry.available.pop()!);\n  }\n\n  // Pool was pre-warmed to MAX_CONNS_PER_REPO during init.  If we're here\n  // with fewer total connections, something leaked — surface the bug rather\n  // than silently creating a connection (which would silence stdout mid-query).\n  const totalConns = entry.available.length + entry.checkedOut;\n  if (totalConns < MAX_CONNS_PER_REPO) {\n    throw new Error(\n      `Connection pool integrity error: expected ${MAX_CONNS_PER_REPO} ` +\n        `connections but found ${totalConns} (${entry.available.length} available, ` +\n        `${entry.checkedOut} checked out)`,\n    );\n  }\n\n  // At capacity — queue the caller with a timeout.\n  return new Promise<lbug.Connection>((resolve, reject) => {\n    const waiter = {\n      resolve: (conn: lbug.Connection) => {\n        clearTimeout(timer);\n        resolve(conn);\n      },\n      reject: (err: Error) => {\n        clearTimeout(timer);\n        reject(err);\n      },\n    };","sourceCodeStart":1147,"sourceCodeEnd":1183,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/ac9a4e9abd8fd3058c070b72c23402a4f887929a/gitnexus/src/core/lbug/pool-adapter.ts#L1147-L1183","documentation":"checkout (gitnexus/src/core/lbug/pool-adapter.ts:941): the pool is pre-warmed to MAX_CONNS_PER_REPO connections at init, so finding available + checkedOut below that total means a connection was checked out and never checked back in — a leak. The guard throws rather than silently creating a replacement, because lazy connection creation would corrupt stdout handling mid-query.","triggerScenarios":"Any executeParameterized call on a repo pool where an earlier call leaked its connection — a code path that took the conn outside the try/finally that performs checkin, or a native error that invalidated a connection without the pool's accounting noticing.","commonSituations":"A GitNexus regression dropping the finally-checkin; native LadybugDB failures that close a connection underneath the pool; long-lived MCP servers that hit the leak after N queries and then fail every query on that repo.","solutions":["Report it as a GitNexus bug with the stack — this is an internal accounting invariant, not a user misconfiguration","Restart the MCP/serve process: a fresh initLbug rebuilds the pool at full size","Upgrade to the latest GitNexus patch in case the leak is already fixed","Note which query preceded the first occurrence and include it in the report"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"const isPoolIntegrityError = (e: unknown): boolean =>\n  e instanceof Error && e.message.startsWith('Connection pool integrity error:');","tryCatchPattern":"try {\n  rows = await executeParameterized(repoId, cypher, params);\n} catch (e) {\n  if (isPoolIntegrityError(e)) {\n    // leaked connection — the pool cannot heal itself; recycle the process and report\n    logger.error(`${e.message} — restarting MCP/serve process; report as a GitNexus bug`);\n    await scheduleProcessRestart();\n  }\n  throw e;\n}","preventionTips":["Always return pooled connections via try/finally checkin — never early-return around a checkout","Keep GitNexus patched — pool accounting fixes land in patch releases","Restart long-lived MCP servers periodically if this leak is observed in your version"],"tags":["gitnexus","ladybugdb","connection-pool","leak","invariant-violation"],"backgroundTag":"connection-leak","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"}