Skip to content

Commit 0673fa1

Browse files
Chain-Foxgzliudan
authored andcommitted
eth/downloader: fix possible data race by inconsistent field protection (ethereum#20690)
1 parent 7330889 commit 0673fa1

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
@@ -566,26 +566,29 @@ func (q *queue) reserveHeaders(p *peerConnection, count int, taskPool map[common
566566

567567
// CancelHeaders aborts a fetch request, returning all pending skeleton indexes to the queue.
568568
func (q *queue) CancelHeaders(request *fetchRequest) {
569+
q.lock.Lock()
570+
defer q.lock.Unlock()
569571
q.cancel(request, q.headerTaskQueue, q.headerPendPool)
570572
}
571573

572574
// CancelBodies aborts a body fetch request, returning all pending headers to the
573575
// task queue.
574576
func (q *queue) CancelBodies(request *fetchRequest) {
577+
q.lock.Lock()
578+
defer q.lock.Unlock()
575579
q.cancel(request, q.blockTaskQueue, q.blockPendPool)
576580
}
577581

578582
// CancelReceipts aborts a body fetch request, returning all pending headers to
579583
// the task queue.
580584
func (q *queue) CancelReceipts(request *fetchRequest) {
585+
q.lock.Lock()
586+
defer q.lock.Unlock()
581587
q.cancel(request, q.receiptTaskQueue, q.receiptPendPool)
582588
}
583589

584590
// Cancel aborts a fetch request, returning all pending hashes to the task queue.
585591
func (q *queue) cancel(request *fetchRequest, taskQueue *prque.Prque, pendPool map[string]*fetchRequest) {
586-
q.lock.Lock()
587-
defer q.lock.Unlock()
588-
589592
if request.From > 0 {
590593
taskQueue.Push(request.From, -int64(request.From))
591594
}

0 commit comments

Comments
 (0)