diff --git a/les/server_handler.go b/les/server_handler.go index fd50a025dcf6..e34be4d3df68 100644 --- a/les/server_handler.go +++ b/les/server_handler.go @@ -127,16 +127,17 @@ func (h *serverHandler) handle(p *peer) error { } defer p.fcClient.Disconnect() + // Disconnect the inbound peer if it's rejected by clientPool + if !h.server.clientPool.connect(p, 0) { + p.Log().Debug("Light Ethereum peer registration failed", "err", errFullClientPool) + return errFullClientPool + } // Register the peer locally if err := h.server.peers.Register(p); err != nil { + h.server.clientPool.disconnect(p) p.Log().Error("Light Ethereum peer registration failed", "err", err) return err } - // Disconnect the inbound peer if it's rejected by clientPool - if h.server.clientPool.connect(p, 0) { - p.Log().Debug("Light Ethereum peer registration failed", "err", errFullClientPool) - return errFullClientPool - } clientConnectionGauge.Update(int64(h.server.peers.Len())) var wg sync.WaitGroup // Wait group used to track all in-flight task routines. @@ -144,8 +145,8 @@ func (h *serverHandler) handle(p *peer) error { connectedAt := mclock.Now() defer func() { wg.Wait() // Ensure all background task routines have exited. - h.server.clientPool.disconnect(p) h.server.peers.Unregister(p.id) + h.server.clientPool.disconnect(p) clientConnectionGauge.Update(int64(h.server.peers.Len())) connectionTimer.Update(time.Duration(mclock.Now() - connectedAt)) }() diff --git a/les/test_helper.go b/les/test_helper.go index 70a724b72af9..79cf323d62db 100644 --- a/les/test_helper.go +++ b/les/test_helper.go @@ -281,6 +281,7 @@ func newTestServerHandler(blocks int, indexers []*core.ChainIndexer, db ethdb.Da server.costTracker, server.freeCapacity = newCostTracker(db, server.config) server.costTracker.testCostList = testCostList(0) // Disable flow control mechanism. server.clientPool = newClientPool(db, 1, 10000, clock, nil) + server.clientPool.setLimits(10000, 10000) // Assign enough capacity for clientpool server.handler = newServerHandler(server, simulation.Blockchain(), db, txpool, func() bool { return true }) if server.oracle != nil { server.oracle.start(simulation)