From baeffa16516b2a68e47c5d6e173ace18a185006d Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Wed, 6 May 2020 18:26:03 +0800 Subject: [PATCH] les: drop the message if the entire p2p connection is stuck --- les/peer.go | 20 +------------------- les/server_handler.go | 2 +- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/les/peer.go b/les/peer.go index d14a5e0d1e..dba239c08c 100644 --- a/les/peer.go +++ b/les/peer.go @@ -164,24 +164,6 @@ func (p *peerCommons) queueSend(f func()) bool { return p.sendQueue.Queue(f) } -// mustQueueSend starts a for loop and retry the caching if failed. -// If the stopCh is closed, then it returns. -func (p *peerCommons) mustQueueSend(f func()) { - for { - // Check whether the stopCh is closed. - select { - case <-p.closeCh: - return - default: - } - // If the function is successfully cached, return. - if p.canQueue() && p.queueSend(f) { - return - } - time.Sleep(retrySendCachePeriod) - } -} - // String implements fmt.Stringer. func (p *peerCommons) String() string { return fmt.Sprintf("Peer %s [%s]", p.id, fmt.Sprintf("les/%d", p.version)) @@ -899,7 +881,7 @@ func (p *clientPeer) updateCapacity(cap uint64) { var kvList keyValueList kvList = kvList.add("flowControl/MRR", cap) kvList = kvList.add("flowControl/BL", cap*bufLimitRatio) - p.mustQueueSend(func() { p.sendAnnounce(announceData{Update: kvList}) }) + p.queueSend(func() { p.sendAnnounce(announceData{Update: kvList}) }) } // freezeClient temporarily puts the client in a frozen state which means all diff --git a/les/server_handler.go b/les/server_handler.go index 9543e6ed98..dd1c37f66d 100644 --- a/les/server_handler.go +++ b/les/server_handler.go @@ -262,7 +262,7 @@ func (h *serverHandler) handleMsg(p *clientPeer, wg *sync.WaitGroup) error { h.server.clientPool.requestCost(p, realCost) } if reply != nil { - p.mustQueueSend(func() { + p.queueSend(func() { if err := reply.send(bv); err != nil { select { case p.errCh <- err: