Skip to content

feat(database/gdb): add MaxIdleConnTime configuration for SetConnMaxIdleTime support#4625

Merged
hailaz merged 1 commit intogogf:masterfrom
lingcoder:hotfix/issue4596
Jan 19, 2026
Merged

feat(database/gdb): add MaxIdleConnTime configuration for SetConnMaxIdleTime support#4625
hailaz merged 1 commit intogogf:masterfrom
lingcoder:hotfix/issue4596

Conversation

@lingcoder
Copy link
Contributor

Summary

  • Add MaxIdleConnTime configuration field to support Go 1.15+ sql.DB.SetConnMaxIdleTime() method
  • Add SetMaxIdleConnTime() method to DB interface and Core implementation
  • Apply configuration during connection pool initialization
  • Add unit tests for the new configuration option

Related Issue

Closes #4596

Changes

File Change
database/gdb/gdb_core_config.go Add MaxIdleConnTime field to ConfigNode, add SetMaxIdleConnTime() method
database/gdb/gdb.go Add interface method, dynamicConfig field, initialization logic
database/gdb/gdb_z_core_config_test.go Add unit test for SetMaxIdleConnTime
database/gdb/gdb_z_core_config_external_test.go Add ConfigNode connection pool settings test

Usage

Configuration file:

database:
  default:
    maxIdleTime: "10s"  # Close idle connections after 10 seconds

Code:

db.SetMaxIdleConnTime(10 * time.Second)

Test Plan

  • Unit tests pass (go test -run "Test_Core_SetMaxConnections|Test_ConfigNode_ConnectionPoolSettings")
  • All database drivers compile successfully (mysql, pgsql, sqlite, clickhouse, dm, mssql, oracle, etc.)
  • No breaking changes - follows Go's default behavior (0 = no idle time limit)

…dleTime support (gogf#4596)

Add support for Go 1.15+ sql.DB.SetConnMaxIdleTime() method:
- Add MaxIdleConnTime field to ConfigNode (json: maxIdleTime)
- Add SetMaxIdleConnTime method to DB interface and Core
- Apply MaxIdleConnTime setting during connection pool initialization
- Add unit tests for the new configuration option

This allows users to configure the maximum idle time for database connections,
which is useful for databases with limited connection licenses (e.g., DamengDB).
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for configuring the maximum idle time for database connections through the MaxIdleConnTime configuration field, enabling use of Go 1.15+'s sql.DB.SetConnMaxIdleTime() method.

Changes:

  • Added MaxIdleConnTime configuration field and setter method to support idle connection timeout
  • Integrated the new configuration into the connection pool initialization logic
  • Added comprehensive unit tests for the new functionality

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
database/gdb/gdb_core_config.go Added MaxIdleConnTime field to ConfigNode struct and implemented SetMaxIdleConnTime() method with documentation
database/gdb/gdb.go Added interface method, MaxIdleConnTime field to dynamicConfig, and initialization logic in getSqlDb()
database/gdb/gdb_z_core_config_test.go Added unit test for SetMaxIdleConnTime() method in existing connection settings test
database/gdb/gdb_z_core_config_external_test.go Added comprehensive test for all connection pool configuration fields including MaxIdleConnTime

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hailaz hailaz merged commit 75f89f1 into gogf:master Jan 19, 2026
24 checks passed
@lingcoder lingcoder deleted the hotfix/issue4596 branch February 28, 2026 00:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gdb: 在配置中增加 maxIdleTime 选项,以支持 SetConnMaxIdleTime

3 participants