Skip to content

Commit

Permalink
fix: avoid scheduling an instance refresh if the context is done
Browse files Browse the repository at this point in the history
  • Loading branch information
jomaresch committed Jan 20, 2024
1 parent ff5ca35 commit 6b5feee
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions internal/alloydb/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,13 @@ func (i *Instance) scheduleRefresh(d time.Duration) *refreshOperation {
// result and schedule a new refresh
i.resultGuard.Lock()
defer i.resultGuard.Unlock()

// instance has been closed, don't schedule anything
if i.ctx.Err() != nil {
i.cur = r
return
}

// if failed, scheduled the next refresh immediately
if r.err != nil {
i.next = i.scheduleRefresh(0)
Expand All @@ -297,12 +304,6 @@ func (i *Instance) scheduleRefresh(d time.Duration) *refreshOperation {
// Update the current results, and schedule the next refresh in
// the future
i.cur = r
select {
case <-i.ctx.Done():
// instance has been closed, don't schedule anything
return
default:
}
t := refreshDuration(time.Now(), i.cur.result.expiry)
i.next = i.scheduleRefresh(t)
})
Expand Down

0 comments on commit 6b5feee

Please sign in to comment.