Skip to content

database/sql: shutdown connections gracefully #42963

@F21

Description

@F21

It would be nice to have a way to ask sql.DB to shutdown its connections gracefully. There's a SetMaxIdleConns() method that can be set to -1 to clear out all idle connections. However, this does not shutdown any active connections gracefully.

Our use-case is due to database credentials being rotated using Vault or AWS's IAM credentials for RDS. In both instances, we are handed dynamically generated usernames and passwords that will be revoked after a certain amount of time. New credentials are then generated.

In order to update the credentials in a given sql.DB instance, we have written a simple wrapper driver that provides the ability to customize the creation of a new connection using the Connector interface via a function hook: https://github.com/Boostport/dynamic-database-config

The only thing that's missing is the ability to signal sql.DB to shutdown all connections gracefully, that is to allow all current queries to complete, but not allow new ones to be scheduled on the current connections and then closing them once the current queries connect. This would then free up connections and force sql.DB to create new connections, which using our driver wrapper would produce connections with the new credentials.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions