{"record":{"id":"1924c443bf55efd2","repo":"ruvnet/ruflo","slug":"failed-to-initialize-connection-pool-error-as","errorCode":null,"errorMessage":"Failed to initialize connection pool: ${(error as Error).message}","messagePattern":"Failed to initialize connection pool: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"v3/@claude-flow/plugins/src/integrations/ruvector/ruvector-bridge.ts","lineNumber":246,"sourceCode":"      this.lastHealthCheck = new Date();\n\n      const connectionResult: ConnectionResult = {\n        connectionId: `conn-${this.connectionId}`,\n        ready: true,\n        serverVersion: result.rows[0]?.version ?? 'unknown',\n        ruVectorVersion: result.rows[0]?.ruvector_version ?? 'N/A',\n        parameters: {\n          host: this.config.host,\n          port: String(this.config.port),\n          database: this.config.database,\n          ssl: String(!!this.config.ssl),\n        },\n      };\n\n      return connectionResult;\n    } catch (error) {\n      this.isConnected = false;\n      throw new Error(`Failed to initialize connection pool: ${(error as Error).message}`);\n    }\n  }\n\n  /**\n   * Load pg module dynamically.\n   */\n  private async loadPg(): Promise<PoolFactory> {\n    try {\n      // Try to import pg\n      const pg: any = await import('pg');\n      return pg.default ?? pg;\n    } catch {\n      throw new Error(\n        'pg (node-postgres) package not found. Install it with: npm install pg'\n      );\n    }\n  }\n","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/plugins/src/integrations/ruvector/ruvector-bridge.ts#L228-L264","documentation":"Wrapper error thrown when creating the pg.Pool or the subsequent verification query fails during initialize(). The original driver message is appended, so the real cause is in the suffix: unreachable host, authentication failure, nonexistent database, SSL negotiation error, or invalid pool settings. The bridge sets isConnected = false before rethrowing.","triggerScenarios":"Wrong host/port/database/credentials in the RuVector config; Postgres behind a firewall or started after the app; ssl required by the server but disabled in config; pgvector extension present but user lacks CREATE EXTENSION rights during the verification step.","commonSituations":"Env vars (PGHOST/PGPASSWORD) not set in the deployed environment; docker-compose startup race where the app beats the DB; connecting to a managed Postgres that enforces TLS while config has ssl: false.","solutions":["Read the appended original message — it names the actual driver failure (ECONNREFUSED, password authentication failed, etc.)","Verify connectivity with the same parameters using psql 'postgres://user:pass@host:port/db?sslmode=require'","Fix config/env: correct host, port, database, user, password, and ssl settings; ensure they reach the process","For startup races, retry initialize() with backoff, and for managed DBs enable ssl or provide the CA cert"],"exampleFix":"// before\nconst bridge = new RuVectorBridge({ host: 'localhost', port: 5432, database: 'ruvector' });\nawait bridge.initialize(); // ECONNREFUSED wrapped\n\n// after\nconst bridge = new RuVectorBridge({\n  host: process.env.PGHOST!,\n  port: Number(process.env.PGPORT ?? 5432),\n  database: process.env.PGDATABASE!,\n  user: process.env.PGUSER,\n  password: process.env.PGPASSWORD,\n  ssl: { rejectUnauthorized: false },\n});\nawait bridge.initialize();","handlingStrategy":"retry","validationCode":"// preflight connectivity with the same params before pool init\nimport net from 'node:net';\nawait new Promise<void>((resolve, reject) => {\n  const s = net.connect(config.port, config.host);\n  s.once('connect', () => { s.destroy(); resolve(); });\n  s.once('error', reject);\n});\nawait bridge.initialize();","typeGuard":null,"tryCatchPattern":"const maxAttempts = 5;\nfor (let attempt = 1; attempt <= maxAttempts; attempt++) {\n  try {\n    await bridge.initialize();\n    break;\n  } catch (err) {\n    const msg = (err as Error).message;\n    if (attempt === maxAttempts || !/ECONNREFUSED|ETIMEDOUT|password authentication/.test(msg)) {\n      throw new Error(`RuVector init failed: ${msg}`);\n    }\n    await sleep(1000 * 2 ** (attempt - 1));\n  }\n}","preventionTips":["Fail fast on config errors (auth, missing DB) but retry transient network errors with backoff","Verify psql connectivity with identical parameters before debugging the library","In containers, add a healthcheck/depends_on for Postgres so the app starts after the DB accepts connections","Log the appended driver message verbatim — it distinguishes auth vs network vs SSL problems"],"tags":["database","postgres","connection-pool","configuration"],"backgroundTag":"database-connection-failed","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","contentChangedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}