From f8e0e8dc550621711d6702966a06c35fe9c99126 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Fri, 29 Aug 2025 15:47:09 +0200 Subject: [PATCH] p2p/discover: add context in waitForNodes --- p2p/discover/table.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/p2p/discover/table.go b/p2p/discover/table.go index 63aa655256..6a1c7494ee 100644 --- a/p2p/discover/table.go +++ b/p2p/discover/table.go @@ -708,7 +708,7 @@ func (tab *Table) deleteNode(n *enode.Node) { } // waitForNodes blocks until the table contains at least n nodes. -func (tab *Table) waitForNodes(n int) bool { +func (tab *Table) waitForNodes(ctx context.Context, n int) error { getlength := func() (count int) { for _, b := range &tab.buckets { count += len(b.entries) @@ -721,7 +721,7 @@ func (tab *Table) waitForNodes(n int) bool { tab.mutex.Lock() if getlength() >= n { tab.mutex.Unlock() - return true + return nil } if ch == nil { // Init subscription. @@ -734,8 +734,10 @@ func (tab *Table) waitForNodes(n int) bool { // Wait for a node add event. select { case <-ch: + case <-ctx.Done(): + return ctx.Err() case <-tab.closeReq: - return false + return errClosed } } }