diff --git a/Makefile b/Makefile index fc86ede..ac54302 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ test-e2e: .PHONY: build clean test run-node run-node2 run-node3 run-example deps tidy fmt vet lint clear-ports -VERSION := 0.52.15 +VERSION := 0.52.16 COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown) DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ) LDFLAGS := -X 'main.version=$(VERSION)' -X 'main.commit=$(COMMIT)' -X 'main.date=$(DATE)' diff --git a/pkg/gateway/gateway.go b/pkg/gateway/gateway.go index ef03844..6057a34 100644 --- a/pkg/gateway/gateway.go +++ b/pkg/gateway/gateway.go @@ -108,13 +108,22 @@ func New(logger *logging.ColoredLogger, cfg *Config) (*Gateway, error) { if dbErr != nil { logger.ComponentWarn(logging.ComponentGeneral, "failed to open rqlite sql db; http orm gateway disabled", zap.Error(dbErr)) } else { + // Configure connection pool with proper timeouts and limits + db.SetMaxOpenConns(25) // Maximum number of open connections + db.SetMaxIdleConns(5) // Maximum number of idle connections + db.SetConnMaxLifetime(5 * time.Minute) // Maximum lifetime of a connection + db.SetConnMaxIdleTime(2 * time.Minute) // Maximum idle time before closing + gw.sqlDB = db orm := rqlite.NewClient(db) gw.ormClient = orm gw.ormHTTP = rqlite.NewHTTPGateway(orm, "/v1/db") + // Set a reasonable timeout for HTTP requests (30 seconds) + gw.ormHTTP.Timeout = 30 * time.Second logger.ComponentInfo(logging.ComponentGeneral, "RQLite ORM HTTP gateway ready", zap.String("dsn", dsn), zap.String("base_path", "/v1/db"), + zap.Duration("timeout", gw.ormHTTP.Timeout), ) } diff --git a/pkg/rqlite/adapter.go b/pkg/rqlite/adapter.go index 81205bf..ec456d3 100644 --- a/pkg/rqlite/adapter.go +++ b/pkg/rqlite/adapter.go @@ -3,6 +3,7 @@ package rqlite import ( "database/sql" "fmt" + "time" _ "github.com/rqlite/gorqlite/stdlib" // Import the database/sql driver ) @@ -21,6 +22,12 @@ func NewRQLiteAdapter(manager *RQLiteManager) (*RQLiteAdapter, error) { return nil, fmt.Errorf("failed to open RQLite SQL connection: %w", err) } + // Configure connection pool with proper timeouts and limits + db.SetMaxOpenConns(25) // Maximum number of open connections + db.SetMaxIdleConns(5) // Maximum number of idle connections + db.SetConnMaxLifetime(5 * time.Minute) // Maximum lifetime of a connection + db.SetConnMaxIdleTime(2 * time.Minute) // Maximum idle time before closing + return &RQLiteAdapter{ manager: manager, db: db,