Skip to content

Commit

Permalink
fix: prevent race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
2color committed Dec 5, 2024
1 parent fe372ac commit 03a4078
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions server_cached_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ func (it *cacheFallbackIter) Next() bool {
return true
}
logger.Infow("no cached addresses found in cacheFallbackIter, dispatching find peers", "peer", id)

it.ongoingLookups.Add(1) // important to increment here since Next() may be called again synchronously
// If a record has no addrs, we dispatch a lookup to find addresses
go it.dispatchFindPeer(*record)
// important to increment here since Next() may be called again synchronously
it.ongoingLookups.Add(1)

return it.Next() // Recursively call Next() to either read from sourceIter or wait for lookup result
}
Expand Down

0 comments on commit 03a4078

Please sign in to comment.