googleapis / go-sql-spanner

Google Cloud Spanner driver for Go's database/sql package.
Apache License 2.0
104 stars 24 forks source link

fix: reconnect after all idle connections close #290

Closed egonelbre closed 2 months ago

egonelbre commented 2 months ago

When all connnections attached to the connector closed then the spanner client and admin client was closed. This is a problem, because the database may still hold on to the connector and may want to make new connections.

This changes the logic such that the connector can reconnect the client when necessary.

olavloite commented 2 months ago

@egonelbre I made a small change to this PR, as removing/adding the connector from the map of driver connectors when all connections were closed caused some flaky test failures, probably due to underlying connections being closed right at the same time as that a new connection was being requested for the same connector. Instead, I've added a Close() method to connector, so it now implements the Closer interface. This method will automatically be called when Database.Close() is called, and this method removes a connector from the map of active connectors.