From 1765712a83a15a5869e8413db24256a37881a944 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Fri, 26 Apr 2024 14:04:19 +0200 Subject: [PATCH] p2p/discover: fix double lock --- p2p/discover/table.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/p2p/discover/table.go b/p2p/discover/table.go index 4fa73c8240..5f9de4096a 100644 --- a/p2p/discover/table.go +++ b/p2p/discover/table.go @@ -369,12 +369,13 @@ loop: tab.revalidation.handleResponse(tab, r) case op := <-tab.addNodeCh: + tab.mutex.Lock() tab.handleAddNode(op) + tab.mutex.Unlock() tab.addNodeHandled <- struct{}{} case op := <-tab.trackRequestCh: tab.handleTrackRequest(op) - // TODO: handle failure by potentially dropping node case <-refresh.C: if refreshDone == nil { @@ -492,6 +493,8 @@ func (tab *Table) removeIP(b *bucket, ip net.IP) { b.ips.Remove(ip) } +// handleAddNode adds the node in the request to the table, if there is space. +// The caller must hold tab.mutex. func (tab *Table) handleAddNode(req addNodeOp) { if req.node.ID() == tab.self().ID() { return @@ -502,8 +505,6 @@ func (tab *Table) handleAddNode(req addNodeOp) { return } - tab.mutex.Lock() - defer tab.mutex.Unlock() b := tab.bucket(req.node.ID()) if tab.bumpInBucket(b, req.node.Node) { // Already in bucket, update record.