From 02aa86e6591d4a70f152d8dc579df25e9aa0cd12 Mon Sep 17 00:00:00 2001
From: rjl493456442 <garyrong0905@gmail.com>
Date: Mon, 14 Aug 2017 13:48:24 +0800
Subject: [PATCH] eth/downloader: exit loop when there is no more available
 task

---
 eth/downloader/downloader.go | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go
index 6ac58140a..13f3b11c9 100644
--- a/eth/downloader/downloader.go
+++ b/eth/downloader/downloader.go
@@ -1093,6 +1093,10 @@ func (d *Downloader) fetchParts(errCancel error, deliveryCh chan dataPack, deliv
 					throttled = true
 					break
 				}
+				// Short circuit if there is no more available task.
+				if pending() == 0 {
+					break
+				}
 				// Reserve a chunk of fetches for a peer. A nil can mean either that
 				// no more headers are available, or that the peer is known not to
 				// have them.
-- 
GitLab