What changed, and why it matters
This commit fixes a minor configuration mismatch in how LND's new SQLite database layer (v2) manages its connection pool. Previously, the default number of idle connections was set to 6, while the default number of open connections was only 2. Go's database library silently limits idle connections to the open-connection cap, so the effective idle pool was already 2, but the configured default was misleading and differed from the older v1 behavior. The change makes the idle default inherit the open-connection default unless the user explicitly overrides it, and adds tests. It is not a security vulnerability.
No security action required. Treat as a normal code-quality/configuration regression fix. Reviewers may verify that the new MaxIdleConns() helper is used consistently and that tests pass.
Security signals we found
No security-relevant signals in commit message or diff
Change is described as a regression fix for default configuration parity, not a security fix
No input validation, privilege boundary, cryptographic, or network changes
Evidence from the diff
In sqldb/v2, SqliteConfig gains a MaxIdleConns() helper that returns MaxIdleConnections if explicitly set, otherwise falls back to MaxConns(). NewSqliteStore now uses cfg.MaxIdleConns() instead of a local defaultMaxIdleConns (6). This aligns the default idle pool with the restored SetMaxOpenConns(2) default from commit e263ea145, matching v1 behavior. Unit tests cover default inheritance and explicit override cases.
Changed components
sqldb/v2/config.gosqldb/v2/sqlite.gosqldb/v2/config_test.goInspect captured patch +56 / −6
diff --git a/sqldb/v2/config.go b/sqldb/v2/config.go
index d0d3351..9e6c3c0 100644
--- a/sqldb/v2/config.go
+++ b/sqldb/v2/config.go
@@ -77,6 +77,16 @@ func (s *SqliteConfig) MaxConns() int {
return DefaultSqliteMaxConns
}
+// MaxIdleConns returns the effective maximum number of idle SQLite
+// connections.
+func (s *SqliteConfig) MaxIdleConns() int {
+ if s.MaxIdleConnections > 0 {
+ return s.MaxIdleConnections
+ }
+
+ return s.MaxConns()
+}
+
// Validate checks that the SqliteConfig values are valid.
func (p *SqliteConfig) Validate() error {
if err := p.QueryConfig.Validate(true); err != nil {
diff --git a/sqldb/v2/config_test.go b/sqldb/v2/config_test.go
index dcf8666..c6e9d21 100644
--- a/sqldb/v2/config_test.go
+++ b/sqldb/v2/config_test.go
@@ -41,3 +41,48 @@ func TestSqliteConfigMaxConns(t *testing.T) {
})
}
}
+
+// TestSqliteConfigMaxIdleConns verifies that SQLite defaults its idle
+// connections to the open connection limit unless the caller overrides it.
+func TestSqliteConfigMaxIdleConns(t *testing.T) {
+ t.Parallel()
+
+ testCases := []struct {
+ name string
+ maxConns int
+ maxIdleConns int
+ expectedIdleConn int
+ }{
+ {
+ name: "default idle limit",
+ expectedIdleConn: DefaultSqliteMaxConns,
+ },
+ {
+ name: "inherits explicit open limit",
+ maxConns: 4,
+ expectedIdleConn: 4,
+ },
+ {
+ name: "explicit idle limit",
+ maxConns: 4,
+ maxIdleConns: 3,
+ expectedIdleConn: 3,
+ },
+ }
+
+ for _, testCase := range testCases {
+ testCase := testCase
+
+ t.Run(testCase.name, func(t *testing.T) {
+ t.Parallel()
+
+ cfg := &SqliteConfig{
+ MaxConnections: testCase.maxConns,
+ MaxIdleConnections: testCase.maxIdleConns,
+ }
+
+ require.Equal(t, testCase.expectedIdleConn,
+ cfg.MaxIdleConns())
+ })
+ }
+}
diff --git a/sqldb/v2/sqlite.go b/sqldb/v2/sqlite.go
index 7529e1c..194565b 100644
--- a/sqldb/v2/sqlite.go
+++ b/sqldb/v2/sqlite.go
@@ -136,18 +136,13 @@ func NewSqliteStore(cfg *SqliteConfig, dbPath string) (*SqliteStore, error) {
err)
}
- maxIdleConns := defaultMaxIdleConns
- if cfg.MaxIdleConnections > 0 {
- maxIdleConns = cfg.MaxIdleConnections
- }
-
connMaxLifetime := defaultConnMaxLifetime
if cfg.ConnMaxLifetime > 0 {
connMaxLifetime = cfg.ConnMaxLifetime
}
db.SetMaxOpenConns(cfg.MaxConns())
- db.SetMaxIdleConns(maxIdleConns)
+ db.SetMaxIdleConns(cfg.MaxIdleConns())
db.SetConnMaxLifetime(connMaxLifetime)
s := &SqliteStore{
Why this scored 18/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.