fix(db): revert to dedicated sockets db connection establishment#1580
fix(db): revert to dedicated sockets db connection establishment#1580waleedlatif1 merged 1 commit intostagingfrom
Conversation
There was a problem hiding this comment.
Greptile Overview
Summary
This pull request reverts a previous commit (ae3a7f0) that apparently caused database connection issues in the socket server components. The changes restore dedicated database connection pools for socket operations with more conservative connection parameters across three key files.The main change involves adjusting database connection pool configurations throughout the socket server infrastructure. In packages/db/index.ts, the shared database connection pool is expanded from 20 to 30 max connections with a longer connect timeout (30 seconds vs 10 seconds), along with comprehensive logging for connection pool initialization. The socket server operations (apps/sim/socket-server/database/operations.ts) now use a dedicated connection pool with 15 max connections, 10-second idle timeout, and 20-second connect timeout. The room manager (apps/sim/socket-server/rooms/manager.ts) gets its own connection settings with 15-second idle timeout and 20-second connect timeout.
This approach creates a multi-tiered database connection strategy where socket operations use dedicated connection pools separate from the main application's shared pool. The extensive logging added to the main database module suggests this change was driven by production connection issues that were difficult to diagnose. The comment "fallback to shared db for compatibility" indicates this is part of a broader architectural pattern to isolate socket operations while maintaining backward compatibility.
Important Files Changed
Changed Files
| Filename | Score | Overview |
|---|---|---|
| packages/db/index.ts | 4/5 | Enhanced main database connection pool with logging, increased limits, and longer timeouts |
| apps/sim/socket-server/database/operations.ts | 4/5 | Reverted to dedicated socket database connection with conservative pool settings |
| apps/sim/socket-server/rooms/manager.ts | 3/5 | Updated room manager database connection with moderate timeout adjustments |
Confidence score: 3/5
- This PR addresses connection stability issues but introduces configuration inconsistencies across different database clients
- Score reflects the revert nature of changes and potential for configuration drift between different connection pools
- Pay close attention to apps/sim/socket-server/rooms/manager.ts for potential connection parameter mismatches with other socket components
Sequence Diagram
sequenceDiagram
participant User
participant SocketServer
participant Database
participant ConnectionPool
User->>SocketServer: "Connect to workflow room"
note over SocketServer: "Socket connection established"
SocketServer->>ConnectionPool: "Get dedicated socket connection"
ConnectionPool-->>SocketServer: "Return postgres connection"
SocketServer->>Database: "Query workflow state"
Database-->>SocketServer: "Return workflow data"
User->>SocketServer: "Send workflow operation"
note right of User: "e.g., add/update block, edge"
SocketServer->>Database: "Begin transaction"
Database-->>SocketServer: "Transaction started"
SocketServer->>Database: "Update workflow timestamp"
Database-->>SocketServer: "Timestamp updated"
SocketServer->>Database: "Execute operation (block/edge/subflow/variable)"
Database-->>SocketServer: "Operation completed"
alt "Auto-connect edge exists"
SocketServer->>Database: "Insert auto-connect edge"
Database-->>SocketServer: "Edge inserted"
end
alt "Subflow block type"
SocketServer->>Database: "Create subflow entry"
Database-->>SocketServer: "Subflow created"
end
alt "Has parent block"
SocketServer->>Database: "Update parent subflow node list"
Database-->>SocketServer: "Parent updated"
end
SocketServer->>Database: "Commit transaction"
Database-->>SocketServer: "Transaction committed"
SocketServer->>User: "Emit operation success"
note over SocketServer,Database: "Dedicated connection pool for socket operations"
3 files reviewed, no comments
This reverts commit ae3a7f0.