Skip to content

Commit 2a5ed1a

Browse files
authored
eth/downloader: fix possible data race by inconsistent field protection (#20690)
1 parent bf1cdd7 commit 2a5ed1a

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

eth/downloader/queue.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,26 +564,29 @@ func (q *queue) reserveHeaders(p *peerConnection, count int, taskPool map[common
564564

565565
// CancelHeaders aborts a fetch request, returning all pending skeleton indexes to the queue.
566566
func (q *queue) CancelHeaders(request *fetchRequest) {
567+
q.lock.Lock()
568+
defer q.lock.Unlock()
567569
q.cancel(request, q.headerTaskQueue, q.headerPendPool)
568570
}
569571

570572
// CancelBodies aborts a body fetch request, returning all pending headers to the
571573
// task queue.
572574
func (q *queue) CancelBodies(request *fetchRequest) {
575+
q.lock.Lock()
576+
defer q.lock.Unlock()
573577
q.cancel(request, q.blockTaskQueue, q.blockPendPool)
574578
}
575579

576580
// CancelReceipts aborts a body fetch request, returning all pending headers to
577581
// the task queue.
578582
func (q *queue) CancelReceipts(request *fetchRequest) {
583+
q.lock.Lock()
584+
defer q.lock.Unlock()
579585
q.cancel(request, q.receiptTaskQueue, q.receiptPendPool)
580586
}
581587

582588
// Cancel aborts a fetch request, returning all pending hashes to the task queue.
583589
func (q *queue) cancel(request *fetchRequest, taskQueue *prque.Prque, pendPool map[string]*fetchRequest) {
584-
q.lock.Lock()
585-
defer q.lock.Unlock()
586-
587590
if request.From > 0 {
588591
taskQueue.Push(request.From, -int64(request.From))
589592
}

0 commit comments

Comments
 (0)