fix(db): revert to dedicated sockets db connection establishment#1581
fix(db): revert to dedicated sockets db connection establishment#1581waleedlatif1 merged 1 commit intomainfrom
Conversation
This reverts commit ae3a7f0.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Greptile Overview
Summary
This PR implements a reversion to dedicated database connection pools for the socket server while optimizing connection pool configurations across the application. The changes address connection pool exhaustion issues by establishing separate database connection management for different application components.The main database pool in packages/db/index.ts receives significant capacity improvements with increased max connections (20 → 30) and extended connection timeout (10s → 30s), along with comprehensive logging for monitoring connection pool behavior. This suggests the main application was experiencing connection pool pressure.
The socket server components (apps/sim/socket-server/rooms/manager.ts and apps/sim/socket-server/database/operations.ts) now maintain their own dedicated database connections with configurations tuned for real-time operations. The room manager uses a smaller pool (max: 3) with moderate timeouts, while the database operations module uses a larger pool (max: 15) with faster connection cycling (10s idle timeout) but more patience for connection establishment (20s connect timeout).
This architecture creates a clear separation between the main application's database needs and the socket server's real-time operation requirements. The socket server's dedicated pools are optimized for frequent, shorter-lived connections typical of WebSocket operations, while the main pool is configured for higher concurrency and longer-running operations.
Important Files Changed
Changed Files
| Filename | Score | Overview |
|---|---|---|
| packages/db/index.ts | 4/5 | Increased main database pool size to 30 connections and added comprehensive connection logging |
| apps/sim/socket-server/rooms/manager.ts | 3/5 | Reverted to dedicated database connection with small pool size (max: 3) and adjusted timeouts |
| apps/sim/socket-server/database/operations.ts | 3/5 | Created dedicated socket database connection with medium pool size (max: 15) and optimized timeouts |
Confidence score: 3/5
- This PR addresses legitimate connection pool issues but introduces complexity through multiple database connection strategies
- Score reflects concerns about connection pool fragmentation and potential inconsistencies across application components
- Pay close attention to socket server files which now maintain separate database connections that could lead to coordination issues
Sequence Diagram
sequenceDiagram
participant App as "Socket Server App"
participant Env as "Environment Config"
participant Operations as "Database Operations"
participant Rooms as "Room Manager"
participant Postgres1 as "Socket DB Pool"
participant Postgres2 as "Shared DB Pool"
participant DB as "PostgreSQL Database"
App->>Env: "Load DATABASE_URL"
App->>Operations: "Initialize database operations module"
Operations->>Postgres1: "Create dedicated socket connection pool (max: 15, idle: 10s)"
Postgres1->>DB: "Establish connection pool"
App->>Rooms: "Initialize room manager"
Rooms->>Postgres2: "Create room manager connection pool (max: 3, idle: 15s)"
Postgres2->>DB: "Establish connection pool"
Note over Operations, Postgres1: "Dedicated socket operations pool"
Note over Rooms, Postgres2: "Dedicated room management pool"
App->>Operations: "Handle socket workflow operation"
Operations->>Postgres1: "Execute transaction via dedicated pool"
Postgres1->>DB: "Persist workflow changes"
DB-->>Postgres1: "Confirm transaction"
Postgres1-->>Operations: "Return result"
Operations-->>App: "Operation complete"
App->>Rooms: "Validate workflow consistency"
Rooms->>Postgres2: "Query via room manager pool"
Postgres2->>DB: "Check for orphaned edges"
DB-->>Postgres2: "Return validation results"
Postgres2-->>Rooms: "Consistency check result"
Rooms-->>App: "Validation complete"
3 files reviewed, no comments
No description provided.