Skip to content

Commit 4ce7dd6

Browse files
committed
Fix uploading in OKHttp3 hanging forever when internet is cut off.
1 parent e66052f commit 4ce7dd6

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/main/java/com/dropbox/core/http/OkHttp3Requestor.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public OutputStream getBody() {
214214
PipedRequestBody pipedBody = new PipedRequestBody();
215215
setBody(pipedBody);
216216

217-
this.callback = new AsyncCallback();
217+
this.callback = new AsyncCallback(pipedBody);
218218
this.call = client.newCall(request.build());
219219
// enqueue the call (async call execution). This allows us to provide streaming uploads.
220220
call.enqueue(callback);
@@ -288,10 +288,12 @@ public Response finish() throws IOException {
288288
}
289289

290290
public static final class AsyncCallback implements Callback {
291+
private PipedRequestBody body;
291292
private IOException error;
292293
private okhttp3.Response response;
293294

294-
private AsyncCallback() {
295+
private AsyncCallback(PipedRequestBody body) {
296+
this.body = body;
295297
this.error = null;
296298
this.response = null;
297299
}
@@ -314,6 +316,7 @@ public synchronized okhttp3.Response getResponse() throws IOException {
314316
@Override
315317
public synchronized void onFailure(Call call, IOException ex) {
316318
this.error = ex;
319+
this.body.close();
317320
notifyAll();
318321
}
319322

0 commit comments

Comments
 (0)