@@ -107,6 +107,11 @@ public DownloadChunkHandler(
107107 ClientDiagnostics clientDiagnostics ,
108108 CancellationToken cancellationToken )
109109 {
110+ // Set bytes transferred to the length of bytes we got back from the initial
111+ // download request
112+ _bytesTransferred = currentTransferred ;
113+ _currentRangeIndex = 0 ;
114+
110115 // Create channel of finished Stage Chunk Args to update the bytesTransferred
111116 // and for ending tasks like commit block.
112117 // The size of the channel should never exceed 50k (limit on blocks in a block blob).
@@ -143,10 +148,6 @@ public DownloadChunkHandler(
143148 _queueCompleteFileDownload = behaviors . QueueCompleteFileDownload
144149 ?? throw Errors . ArgumentNull ( nameof ( behaviors . QueueCompleteFileDownload ) ) ;
145150
146- // Set bytes transferred to the length of bytes we got back from the initial
147- // download request
148- _bytesTransferred = currentTransferred ;
149- _currentRangeIndex = 0 ;
150151 _rangesCount = ranges . Count ;
151152 // Set size of the list of null streams
152153 _rangesCompleted = new ConcurrentDictionary < long , string > ( ) ;
@@ -338,8 +339,9 @@ private async Task InvokeFailedEvent(Exception ex)
338339 /// <param name="bytesDownloaded"></param>
339340 private void UpdateBytesAndRange ( long bytesDownloaded )
340341 {
341- Interlocked . Add ( ref _bytesTransferred , bytesDownloaded ) ;
342- Interlocked . Increment ( ref _currentRangeIndex ) ;
342+ // don't need to use Interlocked since this is the only thread reading and updating these values
343+ _bytesTransferred += bytesDownloaded ;
344+ _currentRangeIndex ++ ;
343345 _reportProgressInBytes ( bytesDownloaded ) ;
344346 }
345347 }
0 commit comments