Skip to content

Commit e9be0d4

Browse files
committed
close verifyTask when length of verifyPeers is 0
1 parent 8929510 commit e9be0d4

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

core/remote_state_verifier.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func (vm *remoteVerifyManager) mainLoop() {
115115
verifyTaskCounter.Dec(1)
116116
verifyTaskSucceedMeter.Mark(1)
117117
verifyTaskExecutionTimer.Update(time.Since(task.startAt))
118-
close(task.terminalCh)
118+
task.Close()
119119
}
120120
vm.taskLock.Unlock()
121121
case <-pruneTicker.C:
@@ -126,7 +126,7 @@ func (vm *remoteVerifyManager) mainLoop() {
126126
delete(vm.tasks, hash)
127127
verifyTaskCounter.Dec(1)
128128
verifyTaskFailedMeter.Mark(1)
129-
close(task.terminalCh)
129+
task.Close()
130130
}
131131
}
132132
vm.taskLock.Unlock()
@@ -140,7 +140,7 @@ func (vm *remoteVerifyManager) mainLoop() {
140140
case <-vm.bc.quit:
141141
vm.taskLock.RLock()
142142
for _, task := range vm.tasks {
143-
close(task.terminalCh)
143+
task.Close()
144144
}
145145
vm.taskLock.RUnlock()
146146
return
@@ -276,6 +276,15 @@ func NewVerifyTask(diffhash common.Hash, header *types.Header, peers verifyPeers
276276
return vt
277277
}
278278

279+
func (vt *verifyTask) Close() {
280+
// It is safe to call close multiple
281+
select {
282+
case <-vt.terminalCh:
283+
default:
284+
close(vt.terminalCh)
285+
}
286+
}
287+
279288
func (vt *verifyTask) Start(verifyCh chan common.Hash) {
280289
vt.startAt = time.Now()
281290

@@ -326,7 +335,7 @@ func (vt *verifyTask) sendVerifyRequest(n int) {
326335
// if has not valid peer, log warning.
327336
if len(validPeers) == 0 {
328337
log.Warn("there is no valid peer for block", "number", vt.blockHeader.Number)
329-
return
338+
vt.Close()
330339
}
331340

332341
if n < len(validPeers) && n > 0 {

0 commit comments

Comments
 (0)