in dialer.go [478:501]
func (d *Dialer) removeCached(
ctx context.Context,
i instance.ConnName, c *monitoredCache, err error,
) {
d.logger.Debugf(
ctx,
"[%v] Removing connection info from cache: %v",
i.String(),
err,
)
// If this instance of monitoredCache is still in the cache, remove it.
// If this instance was already removed from the cache or
// if *a separate goroutine* replaced it with a new instance, do nothing.
key := createKey(i)
d.lock.Lock()
if cachedC, ok := d.cache[key]; ok && cachedC == c {
delete(d.cache, key)
}
d.lock.Unlock()
// Close the monitoredCache, this call is idempotent.
c.Close()
}