From 26193db7cf6717eb1bd0853781d1ca8d5382df5a Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Fri, 20 Jan 2017 11:44:39 +0100 Subject: [PATCH] eth/downloader: ensure PendingNodeData returns 0 inside callback --- eth/downloader/queue.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/eth/downloader/queue.go b/eth/downloader/queue.go index e0435f43d1..aed5635236 100644 --- a/eth/downloader/queue.go +++ b/eth/downloader/queue.go @@ -1096,21 +1096,21 @@ func (q *queue) DeliverNodeData(id string, data [][]byte, callback func(int, boo progressed, nproc, procerr := q.stateScheduler.Process(process, batch) q.stateWriters += 1 go func() { - defer func() { - q.lock.Lock() - q.stateWriters -= 1 - q.lock.Unlock() - // Wake up WaitResults after the state has been written because it might be - // waiting for completion of the pivot block's state download. - q.active.Signal() - }() - if procerr != nil { - // Return processing errors through the callback so the sync gets canceled. - callback(nproc, progressed, procerr) - return + // Wake up WaitResults after the state has been written because it might be + // waiting for completion of the pivot block's state download. + defer q.active.Signal() + + if procerr == nil { + nproc = len(process) + procerr = batch.Write() } - err := batch.Write() - callback(len(process), progressed, err) + // Return processing errors through the callback so the sync gets canceled. The + // 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