From a17dca70095f43a8393d16b8a5567d8963b1ff33 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 20 May 2026 14:04:23 -0700 Subject: [PATCH] fix(filer): don't disable the SQL idle connection pool when unconfigured (#9591) * fix(filer): don't disable the SQL idle connection pool when unconfigured The mysql/mysql2/postgres stores called SetMaxIdleConns(maxIdle) unconditionally, so an unset connection_max_idle (0) actively kept zero idle connections - every query opened and closed a fresh connection instead of reusing the pool. Only apply the value when it's set; otherwise leave database/sql's default idle pool of 2 in place. * comments: shorten idle-pool note * fix(filer): default the SQL idle pool via config, keep explicit 0 honored Apply the idle-pool default at the config layer with SetDefault instead of guarding the SetMaxIdleConns call. An absent connection_max_idle now reads back as 2 (pool stays on), while an explicit 0 flows through to SetMaxIdleConns(0) so operators can still disable idle pooling on purpose. --- weed/filer/mysql/mysql_store.go | 2 ++ weed/filer/mysql2/mysql2_store.go | 2 ++ weed/filer/postgres/postgres_store.go | 2 ++ weed/filer/postgres2/postgres2_store.go | 2 ++ 4 files changed, 8 insertions(+) diff --git a/weed/filer/mysql/mysql_store.go b/weed/filer/mysql/mysql_store.go index cb96dea1d..2e83e7a4d 100644 --- a/weed/filer/mysql/mysql_store.go +++ b/weed/filer/mysql/mysql_store.go @@ -33,6 +33,8 @@ func (store *MysqlStore) GetName() string { } func (store *MysqlStore) Initialize(configuration util.Configuration, prefix string) (err error) { + // Absent key keeps a pooled default; an explicit 0 disables the idle pool. + configuration.SetDefault(prefix+"connection_max_idle", 2) return store.initialize( configuration.GetString(prefix+"dsn"), configuration.GetString(prefix+"upsertQuery"), diff --git a/weed/filer/mysql2/mysql2_store.go b/weed/filer/mysql2/mysql2_store.go index 2bce3c063..82d0c86c2 100644 --- a/weed/filer/mysql2/mysql2_store.go +++ b/weed/filer/mysql2/mysql2_store.go @@ -33,6 +33,8 @@ func (store *MysqlStore2) GetName() string { } func (store *MysqlStore2) Initialize(configuration util.Configuration, prefix string) (err error) { + // Absent key keeps a pooled default; an explicit 0 disables the idle pool. + configuration.SetDefault(prefix+"connection_max_idle", 2) return store.initialize( configuration.GetString(prefix+"createTable"), configuration.GetString(prefix+"upsertQuery"), diff --git a/weed/filer/postgres/postgres_store.go b/weed/filer/postgres/postgres_store.go index 6778bc59e..fa6cb7df6 100644 --- a/weed/filer/postgres/postgres_store.go +++ b/weed/filer/postgres/postgres_store.go @@ -28,6 +28,8 @@ func (store *PostgresStore) GetName() string { } func (store *PostgresStore) Initialize(configuration util.Configuration, prefix string) (err error) { + // Absent key keeps a pooled default; an explicit 0 disables the idle pool. + configuration.SetDefault(prefix+"connection_max_idle", 2) return store.initialize( configuration.GetString(prefix+"upsertQuery"), configuration.GetBool(prefix+"enableUpsert"), diff --git a/weed/filer/postgres2/postgres2_store.go b/weed/filer/postgres2/postgres2_store.go index d563ec322..64e86b9da 100644 --- a/weed/filer/postgres2/postgres2_store.go +++ b/weed/filer/postgres2/postgres2_store.go @@ -33,6 +33,8 @@ func (store *PostgresStore2) GetName() string { } func (store *PostgresStore2) Initialize(configuration util.Configuration, prefix string) (err error) { + // Absent key keeps a pooled default; an explicit 0 disables the idle pool. + configuration.SetDefault(prefix+"connection_max_idle", 2) return store.initialize( configuration.GetString(prefix+"createTable"), configuration.GetString(prefix+"upsertQuery"),