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.
The text was updated successfully, but these errors were encountered:
@kardianos I think CL258360 requires a call to db.Close() which closes the db for good. For my use-case, I'd like to close all the existing connections in a db gracefully without closing the db itself. Since there are no active connections, db can instantiate new connections with the correct credentials using the wrapper driver we published.