in src/connector.ts [126:165]
async loadInstance(opts: ConnectionOptions): Promise<void> {
// in case an instance to that connection name has already
// been setup there's no need to set it up again
const key = this.cacheKey(opts);
const entry = this.get(key);
if (entry) {
if (entry.isResolved()) {
await entry.instance?.checkDomainChanged();
if (!entry.instance?.isClosed()) {
// The instance is open and the domain has not changed.
// use the cached instance.
return;
}
} else if (entry.isError()) {
// The instance failed it's initial refresh. Remove it from the
// cache and throw the error.
this.delete(key);
throw entry.err;
} else {
// The instance initial refresh is in progress.
await entry.promise;
return;
}
}
// Start the refresh and add a cache entry.
const promise = CloudSQLInstance.getCloudSQLInstance({
instanceConnectionName: opts.instanceConnectionName,
domainName: opts.domainName,
authType: opts.authType || AuthTypes.PASSWORD,
ipType: opts.ipType || IpAddressTypes.PUBLIC,
limitRateInterval: opts.limitRateInterval || 30 * 1000, // 30 sec
sqlAdminFetcher: this.sqlAdminFetcher,
failoverPeriod: opts.failoverPeriod,
});
this.set(key, new CacheEntry(promise));
// Wait for the cache entry to resolve.
await promise;
}