Skip to content

Commit de9fb97

Browse files
committed
revert to using table parameter
using it.lookup.tab inside is unsafe Signed-off-by: Csaba Kiraly <[email protected]>
1 parent 3589c0d commit de9fb97

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

p2p/discover/lookup.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func (it *lookupIterator) Next() bool {
189189
if it.lookup.empty() {
190190
// If the lookup is empty right after creation, it means the local table
191191
// is in a degraded state, and we need to wait for it to fill again.
192-
it.lookupFailed(1 * time.Minute)
192+
it.lookupFailed(it.lookup.tab, 1*time.Minute)
193193
it.lookup = nil
194194
continue
195195
}
@@ -209,30 +209,30 @@ func (it *lookupIterator) Next() bool {
209209

210210
// lookupFailed handles failed lookup attempts. This can be called when the table has
211211
// exited, or when it runs out of nodes.
212-
func (it *lookupIterator) lookupFailed(timeout time.Duration) {
213-
ctx, cancel := context.WithTimeout(it.ctx, timeout)
212+
func (it *lookupIterator) lookupFailed(tab *Table, timeout time.Duration) {
213+
tout, cancel := context.WithTimeout(it.ctx, timeout)
214214
defer cancel()
215215

216216
// Wait for Table initialization to complete, in case it is still in progress.
217217
select {
218-
case <-it.lookup.tab.initDone:
219-
case <-ctx.Done():
218+
case <-tab.initDone:
219+
case <-tout.Done():
220220
return
221221
}
222222

223223
// Wait for ongoing refresh operation, or trigger one.
224224
if it.tabRefreshing == nil {
225-
it.tabRefreshing = it.lookup.tab.refresh()
225+
it.tabRefreshing = tab.refresh()
226226
}
227227
select {
228228
case <-it.tabRefreshing:
229229
it.tabRefreshing = nil
230-
case <-ctx.Done():
230+
case <-tout.Done():
231231
return
232232
}
233233

234234
// Wait for the table to fill.
235-
it.lookup.tab.waitForNodes(ctx, 1)
235+
tab.waitForNodes(tout, 1)
236236
}
237237

238238
// Close ends the iterator.

0 commit comments

Comments
 (0)