@@ -84,6 +84,7 @@ public HttpResult UploadStream(Stream stream, string key, string upToken, PutExt
8484 if ( putExtra == null )
8585 {
8686 putExtra = new PutExtra ( ) ;
87+ putExtra . MaxRetryTimes = config . MaxRetryTimes ;
8788 }
8889 if ( putExtra . ProgressHandler == null )
8990 {
@@ -588,7 +589,7 @@ private void processMakeBlocks(Dictionary<long, byte[]> blockDataDict, string up
588589 byte [ ] blockData = blockDataDict [ blockIndex ] ;
589590 ResumeBlocker resumeBlocker = new ResumeBlocker ( doneEvent , blockData , blockIndex , upToken , putExtra ,
590591 resumeInfo , blockMakeResults , progressLock , uploadedBytesDict , fileSize , encodedObjectName ) ;
591- ThreadPool . QueueUserWorkItem ( new WaitCallback ( this . MakeBlock ) , resumeBlocker ) ;
592+ ThreadPool . QueueUserWorkItem ( new WaitCallback ( this . MakeBlockWithRetry ) , resumeBlocker ) ;
592593 }
593594
594595 try
@@ -602,11 +603,37 @@ private void processMakeBlocks(Dictionary<long, byte[]> blockDataDict, string up
602603 }
603604 }
604605
606+ private void MakeBlockWithRetry ( object resumeBlockerObj )
607+ {
608+ ResumeBlocker resumeBlocker = ( ResumeBlocker ) resumeBlockerObj ;
609+ ManualResetEvent doneEvent = resumeBlocker . DoneEvent ;
610+ Dictionary < long , HttpResult > blockMakeResults = resumeBlocker . BlockMakeResults ;
611+ long blockIndex = resumeBlocker . BlockIndex ;
612+ PutExtra putExtra = resumeBlocker . PutExtra ;
613+
614+ HttpResult result = MakeBlock ( resumeBlockerObj ) ;
615+
616+
617+ int retryTimes = 0 ;
618+ while (
619+ retryTimes < putExtra . MaxRetryTimes &&
620+ UploadUtil . ShouldRetry ( result . Code , result . RefCode )
621+ )
622+ {
623+ result = MakeBlock ( resumeBlockerObj ) ;
624+ retryTimes += 1 ;
625+ }
626+
627+ //return the http result
628+ blockMakeResults . Add ( blockIndex , result ) ;
629+ doneEvent . Set ( ) ;
630+ }
631+
605632 /// <summary>
606633 /// 创建块(携带首片数据),v1检查CRC32,v2检查md5
607634 /// </summary>
608635 /// <param name="resumeBlockerObj">创建分片上传的块请求</param>
609- private void MakeBlock ( object resumeBlockerObj )
636+ private HttpResult MakeBlock ( object resumeBlockerObj )
610637 {
611638 ResumeBlocker resumeBlocker = ( ResumeBlocker ) resumeBlockerObj ;
612639 ManualResetEvent doneEvent = resumeBlocker . DoneEvent ;
@@ -632,7 +659,7 @@ private void MakeBlock(object resumeBlockerObj)
632659 result . RefText += string . Format ( "[{0}] [ResumableUpload] Info: upload task is aborted, mkblk {1}\n " ,
633660 DateTime . Now . ToString ( "yyyy-MM-dd HH:mm:ss.ffff" ) , blockIndex ) ;
634661 blockMakeResults . Add ( blockIndex , result ) ;
635- return ;
662+ return result ;
636663 }
637664 else
638665 {
@@ -658,7 +685,7 @@ private void MakeBlock(object resumeBlockerObj)
658685 {
659686 result = HttpResult . InvalidToken ;
660687 doneEvent . Set ( ) ;
661- return ;
688+ return result ;
662689 }
663690
664691 string uploadHost = this . config . UpHost ( ak , bucket ) ;
@@ -793,9 +820,7 @@ private void MakeBlock(object resumeBlockerObj)
793820 }
794821 }
795822
796- //return the http result
797- blockMakeResults . Add ( blockIndex , result ) ;
798- doneEvent . Set ( ) ;
823+ return result ;
799824 }
800825
801826 /// <summary>
0 commit comments