mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 07:06:42 +00:00
eth/downloader: ensure PendingNodeData returns 0 inside callback
This commit is contained in:
parent
e9313c7099
commit
26193db7cf
1 changed files with 14 additions and 14 deletions
|
|
@ -1096,21 +1096,21 @@ func (q *queue) DeliverNodeData(id string, data [][]byte, callback func(int, boo
|
||||||
progressed, nproc, procerr := q.stateScheduler.Process(process, batch)
|
progressed, nproc, procerr := q.stateScheduler.Process(process, batch)
|
||||||
q.stateWriters += 1
|
q.stateWriters += 1
|
||||||
go func() {
|
go func() {
|
||||||
defer func() {
|
// Wake up WaitResults after the state has been written because it might be
|
||||||
q.lock.Lock()
|
// waiting for completion of the pivot block's state download.
|
||||||
q.stateWriters -= 1
|
defer q.active.Signal()
|
||||||
q.lock.Unlock()
|
|
||||||
// Wake up WaitResults after the state has been written because it might be
|
if procerr == nil {
|
||||||
// waiting for completion of the pivot block's state download.
|
nproc = len(process)
|
||||||
q.active.Signal()
|
procerr = batch.Write()
|
||||||
}()
|
|
||||||
if procerr != nil {
|
|
||||||
// Return processing errors through the callback so the sync gets canceled.
|
|
||||||
callback(nproc, progressed, procerr)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
err := batch.Write()
|
// Return processing errors through the callback so the sync gets canceled. The
|
||||||
callback(len(process), progressed, err)
|
// number of writers is decremented prior to the call so PendingNodeData will
|
||||||
|
// return zero when the callback runs.
|
||||||
|
q.lock.Lock()
|
||||||
|
q.stateWriters -= 1
|
||||||
|
q.lock.Unlock()
|
||||||
|
callback(nproc, progressed, procerr)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// If none of the data items were good, it's a stale delivery
|
// If none of the data items were good, it's a stale delivery
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue