@@ -192,6 +192,12 @@ private boolean isCancelled() {
192192 }
193193
194194 private void nextTask (final int offset , final int retried , final URI address ) {
195+ if (isCancelled ()) {
196+ ResponseInfo i = ResponseInfo .cancelled ();
197+ completionHandler .complete (key , i , null );
198+ return ;
199+ }
200+
195201 if (offset == size ) {
196202 CompletionHandler complete = new CompletionHandler () {
197203 @ Override
@@ -203,13 +209,7 @@ public void complete(ResponseInfo info, JSONObject response) {
203209 return ;
204210 }
205211
206- if (isCancelled ()) {
207- ResponseInfo i = ResponseInfo .cancelled ();
208- completionHandler .complete (key , i , null );
209- return ;
210- }
211-
212- if (isNotQiniu (info ) || (info .needRetry () && retried < config .retryMax )) {
212+ if ((isNotQiniu (info ) || info .needRetry ()) && retried < config .retryMax ) {
213213 nextTask (offset , retried + 1 , config .upBackup .address );
214214 return ;
215215 }
@@ -236,27 +236,22 @@ public void onProgress(int bytesWritten, int totalSize) {
236236 @ Override
237237 public void complete (ResponseInfo info , JSONObject response ) {
238238 if (!info .isOK ()) {
239- if (isCancelled ()) {
240- ResponseInfo i = ResponseInfo .cancelled ();
241- completionHandler .complete (key , i , null );
242- return ;
243- }
244- if (info .statusCode == 701 ) {
245- nextTask ((offset / Configuration .BLOCK_SIZE ) * Configuration .BLOCK_SIZE , retried , address );
239+ if (info .statusCode == 701 && retried < config .retryMax ) {
240+ nextTask ((offset / Configuration .BLOCK_SIZE ) * Configuration .BLOCK_SIZE , retried + 1 , address );
246241 return ;
247242 }
248243
249- if (! isNotQiniu (info ) && ( retried >= config . retryMax || ! info .needRetry ())) {
250- completionHandler . complete ( key , info , null );
244+ if (( isNotQiniu (info ) || info .needRetry ()) && retried < config . retryMax ) {
245+ nextTask ( offset , retried + 1 , config . upBackup . address );
251246 return ;
252247 }
253248
254- nextTask ( offset , retried + 1 , config . upBackup . address );
249+ completionHandler . complete ( key , info , response );
255250 return ;
256251 }
257252 String context = null ;
258253
259- if (response == null ) {
254+ if (response == null && retried < config . retryMax ) {
260255 nextTask (offset , retried + 1 , config .upBackup .address );
261256 return ;
262257 }
@@ -267,7 +262,7 @@ public void complete(ResponseInfo info, JSONObject response) {
267262 } catch (JSONException e ) {
268263 e .printStackTrace ();
269264 }
270- if (context == null || crc != ResumeUploader .this .crc32 ) {
265+ if (( context == null || crc != ResumeUploader .this .crc32 ) && retried < config . retryMax ) {
271266 nextTask (offset , retried + 1 , config .upBackup .address );
272267 return ;
273268 }
0 commit comments