ruvnet/ruflo · error
Connection pool already initialized
Error message
Connection pool already initialized
What it means
Thrown by the connection pool manager's initialize() when this.pool is already set. The manager supports exactly one pg.Pool per instance; a second initialize() would leak the existing pool and duplicate event handlers, so it is rejected.
Source
Thrown at v3/@claude-flow/plugins/src/integrations/ruvector/ruvector-bridge.ts:191
constructor(config: RuVectorConfig) {
super();
this.config = config;
this.retryConfig = config.retry ?? {
maxAttempts: 3,
initialDelayMs: 1000,
maxDelayMs: 30000,
backoffMultiplier: 2,
jitter: true,
};
}
/**
* Initialize the connection pool.
*/
async initialize(): Promise<ConnectionResult> {
if (this.pool) {
throw new Error('Connection pool already initialized');
}
const poolConfig = this.buildPoolConfig();
try {
// Dynamically import pg to avoid bundling issues
const pg = await this.loadPg();
this.pool = new pg.Pool(poolConfig);
// Set up event handlers
this.pool.on('connect', () => {
this.connectionId++;
this.emit('connection:open', {
connectionId: `conn-${this.connectionId}`,
host: this.config.host,
port: this.config.port,
database: this.config.database,
});View on GitHub (pinned to fa13ee4ad6)
Solutions
- Make initialize() idempotent at the call site: skip when the manager already reports a live pool / isConnected
- Centralize initialization in one bootstrap function and pass the ready manager to consumers
- Call shutdown()/close() before intentionally re-initializing (e.g. config reload)
Example fix
// before
await bridge.initialize();
await bridge.initialize(); // throws
// after
await bridge.initialize();
if (!isConnected(bridge)) {
await bridge.initialize();
} Defensive patterns
Strategy: validation
Validate before calling
// expose/simulate a connected check before init
async function ensureInitialized(bridge: RuVectorBridge): Promise<void> {
if (isConnected(bridge)) return; // pool exists
await bridge.initialize();
} Type guard
const isBridgeReady = (b: { isConnected?: boolean }): boolean =>
b.isConnected === true; Try / catch
try {
await bridge.initialize();
} catch (err) {
if (err instanceof Error && err.message === 'Connection pool already initialized') {
return; // already up — treat as success
}
throw err;
} Prevention
- Initialize the bridge exactly once in a bootstrap function and share the ready instance
- Treat 'already initialized' as idempotent success in wrappers
- Call shutdown/close before re-initializing on config reload, and reset the cached instance on hot-reload
When it happens
Trigger: Calling initialize() in both application startup and a plugin's onMount; retry middleware re-invoking initialize() after a health-check flap on the same instance; module imported twice (ESM/CJS dual packaging) so two code paths both initialize the singleton.
Common situations: Framework hot-reload (nest dev mode, next dev) re-running init code against a cached module; refactoring that moved initialize() into a helper called from two places; tests sharing a module-level manager across cases.
Related errors
- Connection pool not initialized
- Connection pool is shutting down
- Failed to initialize connection pool: ${(error as Error).mes
- RuVector Bridge not initialized. Call initialize() first.
- Transaction already active
AI-assisted analysis of ruvnet/ruflo@fa13ee4ad6 (2026-08-18).
Data as JSON: /api/errors/38c38eefef6a0650.
Report an issue: GitHub.