Skip to content

Commit

Permalink
fix: re-use existing connection info on force refresh (#602)
Browse files Browse the repository at this point in the history
Rather than immediately discard the current connection info, this commit
keeps the current info available in case temporary network issues have
caused the failure. When the refresh operation completes, it will update
the connection info with a refreshed value.
  • Loading branch information
enocom committed Aug 15, 2023
1 parent 314e180 commit d049851
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions internal/cloudsql/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,17 +259,16 @@ func (i *Instance) UpdateRefresh(cfg RefreshCfg) {
}

// ForceRefresh triggers an immediate refresh operation to be scheduled and
// used for future connection attempts.
// used for future connection attempts. Until the refresh completes, the
// existing connection info will be available for use.
func (i *Instance) ForceRefresh() {
i.refreshLock.Lock()
defer i.refreshLock.Unlock()
// If the next refresh hasn't started yet, we can cancel it and start
// an immediate one
// If the next refresh hasn't started yet, we can cancel it and start an
// immediate one
if i.next.cancel() {
i.next = i.scheduleRefresh(0)
}
// block all sequential connection attempts on the next refresh operation
i.cur = i.next
}

// refreshOperation returns the most recent refresh operation
Expand Down

0 comments on commit d049851

Please sign in to comment.