Skip to content

Commit

Permalink
Merge pull request #68 from coinbase/patrick/reconciler-panic
Browse files Browse the repository at this point in the history
Handle empty inactive queue correctly
  • Loading branch information
patrick-ogrady authored Jul 16, 2020
2 parents 5b24300 + e9b34db commit 3d021f5
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,11 +641,24 @@ func (r *Reconciler) reconcileInactiveAccounts(
}

r.inactiveQueueMutex.Lock()
nextValidIndex := r.inactiveQueue[0].LastCheck.Index + r.inactiveFrequency
if len(r.inactiveQueue) > 0 &&
(r.inactiveQueue[0].LastCheck == nil || // block is set to nil when loaded from previous run
nextValidIndex <= head.Index) {
nextAcct := r.inactiveQueue[0]
if len(r.inactiveQueue) == 0 {
r.inactiveQueueMutex.Unlock()
if r.debugLogging {
log.Println(
"no accounts ready for inactive reconciliation (0 accounts in queue)",
)
}
time.Sleep(inactiveReconciliationSleep)
continue
}

nextAcct := r.inactiveQueue[0]
nextValidIndex := int64(-1)
if nextAcct.LastCheck != nil { // block is set to nil when loaded from previous run
nextValidIndex = nextAcct.LastCheck.Index + r.inactiveFrequency
}

if nextValidIndex <= head.Index {
r.inactiveQueue = r.inactiveQueue[1:]
r.inactiveQueueMutex.Unlock()

Expand Down

0 comments on commit 3d021f5

Please sign in to comment.