database/sql: shutdown connections gracefully #42963
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
It would be nice to have a way to ask
sql.DB
to shutdown its connections gracefully. There's aSetMaxIdleConns()
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 theConnector
interface via a function hook: https://github.com/Boostport/dynamic-database-configThe 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 forcesql.DB
to create new connections, which using our driver wrapper would produce connections with the new credentials.The text was updated successfully, but these errors were encountered: