mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
les: protect field access with lock to avoid possible data race
This commit is contained in:
parent
96490a10be
commit
e228f66e21
2 changed files with 9 additions and 3 deletions
|
|
@ -125,7 +125,10 @@ func (h *clientHandler) handle(p *peer) error {
|
|||
serverConnectionGauge.Update(int64(h.backend.peers.Len()))
|
||||
}()
|
||||
|
||||
h.fetcher.announce(p, p.headInfo)
|
||||
p.lock.RLock()
|
||||
headInfo := p.headInfo
|
||||
p.lock.RUnlock()
|
||||
h.fetcher.announce(p, headInfo)
|
||||
|
||||
// pool entry can be nil during the unit test.
|
||||
if p.poolEntry != nil {
|
||||
|
|
|
|||
|
|
@ -481,7 +481,10 @@ func (f *clientPool) setCapacity(c *clientInfo, capacity uint64) error {
|
|||
f.connectedCap += capacity - oldCapacity
|
||||
c.balanceTracker.setCapacity(capacity)
|
||||
f.connectedQueue.Update(c.queueIndex)
|
||||
if f.connectedCap > f.capLimit {
|
||||
f.lock.Lock()
|
||||
capLimit := f.capLimit
|
||||
f.lock.Unlock()
|
||||
if f.connectedCap > capLimit {
|
||||
var kickList []*clientInfo
|
||||
kick := true
|
||||
f.connectedQueue.MultiPop(func(data interface{}, priority int64) bool {
|
||||
|
|
@ -491,7 +494,7 @@ func (f *clientPool) setCapacity(c *clientInfo, capacity uint64) error {
|
|||
if client == c {
|
||||
kick = false
|
||||
}
|
||||
return kick && (f.connectedCap > f.capLimit)
|
||||
return kick && (f.connectedCap > capLimit)
|
||||
})
|
||||
if kick {
|
||||
now := mclock.Now()
|
||||
|
|
|
|||
Loading…
Reference in a new issue