diff --git a/cmd/api/main.go b/cmd/api/main.go index 45aaca540..26acbedfc 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -19,6 +19,7 @@ package main import ( "context" "crypto/tls" + "database/sql" "fmt" "net/http" "path" @@ -67,9 +68,6 @@ import ( "k8s.io/apimachinery/pkg/util/wait" ) -// The default number of connections to use -const defaultDatabaseConnections = 10 - func main() { serverConfig := config.Get() @@ -122,19 +120,25 @@ func main() { log.Fatalf("Failed to connect to database: %v", err) } - sqlDB, err := db.DB() + var sqlDB *sql.DB // Set DB connection limits maxIdle := serverConfig.DB_MAX_IDLE_CONNECTIONS maxOpen := serverConfig.DB_MAX_OPEN_CONNECTIONS - if maxOpen < 1 { - maxOpen = defaultDatabaseConnections + if maxOpen > 0 { + sqlDB, err = db.DB() + if err != nil { + log.Fatalf("Error getting database configuration for updating max open connections: %s", err.Error()) + } + sqlDB.SetMaxOpenConns(maxOpen) } - if maxIdle < 1 { - maxIdle = defaultDatabaseConnections + if maxIdle > 0 { + sqlDB, err = db.DB() + if err != nil { + log.Fatalf("Error getting database configuration for updating max open connections: %s", err.Error()) + } + sqlDB.SetMaxIdleConns(maxIdle) } - sqlDB.SetMaxIdleConns(maxIdle) - sqlDB.SetMaxOpenConns(maxOpen) // Set grpc worker pool grpcWorkers := serverConfig.GRPC_WORKER_POOL