GoogleCloudPlatform / cloud-sql-go-connector

A Go library for connecting securely to your Cloud SQL instances
Apache License 2.0
109 stars 29 forks source link

feat: Automatically reset connection when the DNS record changes. #868

Closed hessjcg closed 2 weeks ago

hessjcg commented 2 weeks ago

When a connection is configured using a DNS domain name, the connector will poll the DNS TXT record every 30 seconds. If the value of the DNS record changes, the connector will close all connections to the old instance, and direct new connections to the updated instance.

Part of https://github.com/GoogleCloudPlatform/cloud-sql-go-connector/issues/842

hessjcg commented 2 weeks ago

This supersedes #844 and #865.

hessjcg commented 2 weeks ago

Based on our discussion, I have updated Dialer.cache to use a cache key that identifies an entry either by "project:region:instance" or by "domainName", not the combination "project:region:instance" + "domainName". I also simplified the logic in Dialer.connectionInfoCache() so that it no longer checks if a domain name value is stale before returning existing cache entries.