go.gorm.connection_pool
Scalability
High
Detects missing or misconfigured GORM connection pool settings.
Why It Matters
Section titled “Why It Matters”Missing connection pool configuration:
- Connection exhaustion — Too many connections overwhelm database
- Resource waste — Idle connections consume memory
- Timeouts — No connection reuse leads to slow queries
Example
Section titled “Example”// ❌ Before (no pool configuration)db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})// ✅ After (with connection pool settings)db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})if err != nil { log.Fatal(err)}
sqlDB, err := db.DB()if err != nil { log.Fatal(err)}
sqlDB.SetMaxIdleConns(10)sqlDB.SetMaxOpenConns(100)sqlDB.SetConnMaxLifetime(time.Hour)sqlDB.SetConnMaxIdleTime(10 * time.Minute)What Unfault Detects
Section titled “What Unfault Detects”- Missing SetMaxOpenConns
- Missing SetMaxIdleConns
- Missing SetConnMaxLifetime
- Unreasonable pool size values
Auto-Fix
Section titled “Auto-Fix”Unfault can add appropriate connection pool configuration based on common best practices.