@@ -359,15 +359,20 @@ impl ParallelDownloadProcessorInner {
359359 . set ( RANGE . as_str ( ) , & range_header)
360360 . call ( )
361361 . context ( "GET ranged request failed" ) ?;
362+
362363 // let addr = get_range_response.remote_addr();
363364 // debug!("Chunk {chunk} from {addr:?}");
364- if get_range_response. status ( ) != StatusCode :: PARTIAL_CONTENT {
365- bail ! (
366- "Response to range request has an unexpected status code (expected {}, found {})" ,
367- StatusCode :: PARTIAL_CONTENT ,
368- get_range_response. status( )
369- )
370- }
365+ anyhow:: ensure!(
366+ ( get_range_response. status( ) == StatusCode :: PARTIAL_CONTENT )
367+ || ( get_range_response. status( ) == StatusCode :: OK ) ,
368+ "Response to range request has an unexpected status code (expected [{}], found {})" ,
369+ [
370+ StatusCode :: PARTIAL_CONTENT . to_string( ) ,
371+ StatusCode :: OK . to_string( )
372+ ]
373+ . join( "," ) ,
374+ get_range_response. status( )
375+ ) ;
371376
372377 let range_size = range_end_inclusive
373378 . saturating_sub ( range_start)
@@ -508,6 +513,8 @@ impl ParallelDownloadProcessor {
508513 work_queue : & crossbeam_channel:: Receiver < DlWorkOrder > ,
509514 chain : & Network ,
510515 ) {
516+ const GET_RANGE_NUM_OF_TRIES : u8 = 5 ;
517+
511518 debug ! ( "Worker {worker_id} started" ) ;
512519
513520 // Each worker has its own http_client, so there is no cross worker pathology
@@ -531,23 +538,23 @@ impl ParallelDownloadProcessor {
531538 error ! ( "Next chunk delay overflow" ) ;
532539 }
533540 }
534- let mut retries = 0u8 ;
535- let mut block;
541+ let mut block = None ;
536542 // debug!("Worker {worker_id} DL chunk {next_chunk}");
537- loop {
543+ for attempt in 1u8 ..= GET_RANGE_NUM_OF_TRIES {
538544 block = match params. get_range ( & http_agent, next_chunk) {
539545 Ok ( block) => Some ( block) ,
540546 Err ( error) => {
541- error ! ( "Error getting chunk: {:?}, error: {:?}" , next_chunk, error) ;
547+ error ! (
548+ "Error getting chunk: {next_chunk:?}, error: {error:?}, attempt: {attempt}" ,
549+ ) ;
542550 None
543551 } ,
544552 } ;
545553
546554 // Quickly retry on error, in case its transient.
547- if block. is_some ( ) || retries > 3 {
555+ if block. is_some ( ) {
548556 break ;
549557 }
550- retries = retries. saturating_add ( 1 ) ;
551558 }
552559 // debug!("Worker {worker_id} DL chunk done {next_chunk}: {retries}");
553560
0 commit comments