Skip to content

Commit 50e2e06

Browse files
committed
修复部分取消操作任然进入重试流程
1 parent 08391ff commit 50e2e06

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

library/src/main/java/com/qiniu/android/http/ResponseInfo.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,10 @@ public boolean needSwitchServer() {
194194
}
195195

196196
public boolean needRetry() {
197-
return !isCancelled() && (needSwitchServer() || statusCode == 406
198-
|| (statusCode == 200 && error != null));
197+
return !isCancelled() && (
198+
needSwitchServer() || statusCode == 406 ||
199+
(statusCode == 200 && error != null) || (isNotQiniu() && !upToken.hasReturnUrl())
200+
);
199201
}
200202

201203
public boolean isNotQiniu() {

library/src/main/java/com/qiniu/android/storage/FormUploader.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,7 @@ public void complete(ResponseInfo info, JSONObject response) {
124124
if (info.isOK()) {
125125
options.progressHandler.progress(key, 1.0);
126126
completionHandler.complete(key, info, response);
127-
} else if (options.cancellationSignal.isCancelled()) {
128-
ResponseInfo i = ResponseInfo.cancelled(token);
129-
completionHandler.complete(key, i, null);
130-
} else if (info.needRetry() || (info.isNotQiniu() && !token.hasReturnUrl())) {
127+
} else if (info.needRetry()) {
131128
final String upHostRetry = config.zone.upHost(token.token, config.useHttps, upHost);
132129
Log.d("Qiniu.FormUploader", "retry upload first time use up host " + upHostRetry);
133130
CompletionHandler retried = new CompletionHandler() {
@@ -136,15 +133,15 @@ public void complete(ResponseInfo info, JSONObject response) {
136133
if (info.isOK()) {
137134
options.progressHandler.progress(key, 1.0);
138135
completionHandler.complete(key, info, response);
139-
} else if (info.needRetry() || (info.isNotQiniu() && !token.hasReturnUrl())) {
136+
} else if (info.needRetry()) {
140137
final String upHostRetry2 = config.zone.upHost(token.token, config.useHttps, upHostRetry);
141138
Log.d("Qiniu.FormUploader", "retry upload second time use up host " + upHostRetry2);
142139
CompletionHandler retried2 = new CompletionHandler() {
143140
@Override
144141
public void complete(ResponseInfo info2, JSONObject response2) {
145142
if (info2.isOK()) {
146143
options.progressHandler.progress(key, 1.0);
147-
} else if (info2.needRetry() || (info2.isNotQiniu() && !token.hasReturnUrl())) {
144+
} else if (info2.needRetry()) {
148145
config.zone.frozenDomain(upHostRetry2);
149146
}
150147
completionHandler.complete(key, info2, response2);
@@ -256,7 +253,7 @@ private static ResponseInfo syncUpload0(Client client, Configuration config, byt
256253
}
257254

258255
//retry for the first time
259-
if (info.needRetry() || (info.isNotQiniu() && !token.hasReturnUrl())) {
256+
if (info.needRetry()) {
260257
if (info.isNetworkBroken() && !AndroidNetwork.isNetWorkReady()) {
261258
options.netReadyHandler.waitReady();
262259
if (!AndroidNetwork.isNetWorkReady()) {
@@ -269,7 +266,7 @@ private static ResponseInfo syncUpload0(Client client, Configuration config, byt
269266
Log.d("Qiniu.FormUploader", "sync upload retry first time use up host " + upHostRetry);
270267
info = client.syncMultipartPost(upHostRetry, args, token);
271268

272-
if (info.needRetry() || (info.isNotQiniu() && !token.hasReturnUrl())) {
269+
if (info.needRetry()) {
273270
if (info.isNetworkBroken() && !AndroidNetwork.isNetWorkReady()) {
274271
options.netReadyHandler.waitReady();
275272
if (!AndroidNetwork.isNetWorkReady()) {
@@ -280,7 +277,7 @@ private static ResponseInfo syncUpload0(Client client, Configuration config, byt
280277
String upHostRetry2 = config.zone.upHost(token.token, config.useHttps, upHostRetry);
281278
Log.d("Qiniu.FormUploader", "sync upload retry second time use up host " + upHostRetry2);
282279
info = client.syncMultipartPost(upHostRetry2, args, token);
283-
if (info.needRetry() || (info.isNotQiniu() && !token.hasReturnUrl())) {
280+
if (info.needRetry()) {
284281
config.zone.frozenDomain(upHostRetry2);
285282
}
286283
}

library/src/main/java/com/qiniu/android/storage/ResumeUploader.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,13 @@ public void complete(ResponseInfo info, JSONObject response) {
231231
return;
232232
}
233233

234-
String upHostRetry = config.zone.upHost(token.token, config.useHttps, upHost);
235-
if (upHostRetry != null
236-
&& ((info.isNotQiniu() && !token.hasReturnUrl() || info.needRetry())
237-
&& retried < config.retryMax)) {
238-
nextTask(offset, retried + 1, upHostRetry);
239-
return;
234+
// mkfile ,允许多重试一次
235+
if (info.needRetry() && retried < config.retryMax + 1) {
236+
String upHostRetry = config.zone.upHost(token.token, config.useHttps, upHost);
237+
if (upHostRetry != null) {
238+
nextTask(offset, retried + 1, upHostRetry);
239+
return;
240+
}
240241
}
241242
completionHandler.complete(key, info, response);
242243
}
@@ -269,6 +270,11 @@ public void complete(ResponseInfo info, JSONObject response) {
269270
}
270271
}
271272

273+
if (info.isCancelled()) {
274+
completionHandler.complete(key, info, response);
275+
return;
276+
}
277+
272278
String upHostRetry = config.zone.upHost(token.token, config.useHttps, upHost);
273279
if (!isChunkOK(info, response)) {
274280
if (info.statusCode == 701 && retried < config.retryMax) {

0 commit comments

Comments
 (0)