If you open DB with db.Open, yes, you will need to call db.Close(). Without that it will keep alive a pool of connections to your remote database. -Daniel
On Monday, October 31, 2016 at 10:33:06 PM UTC-7, Francis Chuang wrote: > > I want to use Vault <https://github.com/hashicorp/vault> to manage and > rotate the usernames and passwords to my databases. > > If I open a connection: db, err := sql.Open("mysql", "...."), and then > later on, open a new connection due to the username/password being rotated: > db, err = sql.Open("mysql", "...") //no new variables created, > will the original sql instance leak? I want to avoid having to force all > current queries and executions on the old db to terminate using Close(), as > I would need to have some mutex to act as a gatekeeper for all interactions > with the database, which would be quite complex. > > Ideally, I would prefer the following: > 1. New username/password pair received and sql.Open() is called. > 2. Old db instance is still being used by a few goroutines as they still > hold references to the old sql instance. > 3. Goroutines finishes and no longer hold references to the old sql > instance. The old sql instance is GC'd. Is this possible without calling > Close()? > 4. New goroutines are launched and they use the new sql instance. > > Cheers, > Francis > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.