aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Thierer <tobiast@google.com>2017-01-24 17:43:03 +0000
committerTobias Thierer <tobiast@google.com>2017-01-24 19:33:18 +0000
commit715f88092afc34bbe129118fa9ed737ad38ec050 (patch)
tree596aea6e32250865c9141c116649bd83e5a95c6f
parent0663ccec7ffe3cf4c6d7e9beb40ba11af96f3152 (diff)
downloadokhttp-715f88092afc34bbe129118fa9ed737ad38ec050.tar.gz
OkHttp quick fix: canceled StreamAllocations can never recover
When a HttpURLConnection is disconnected in the middle of connecting, this can lead to an infinite loop because: - StreamAllocation.findConnection() immediately throws (before advancing the RouteSelector) - StreamAllocation.recover() returns true, indicating that a retry is permissible - higher level logic then retries the connection indefinitely in a busy loop This bug does not occur in the latest version of OkHttp (3.5) but can be reproduced directly on top of OkHttp 2.7.5. To give us more time to figure out the best fix, this CL makes the narrowest possible fix for the concrete behavior observed in the wild. There are related cases where StreamAllocation.recover() returns true but findConnection() immediately throws; these have not been observed and are not addressed by this CL: - StreamAllocation.released; this case looks at first glance like it is not reachable via publicly exposed API (HttpURLConnection) - canceled case for recover(IOException e, Sink requestBodyOut): touching this breaks OkHttp's CallTest.canceledBeforeIOSignalsOnFailure*() because the reported error message becomes something like "Socket closed", rather than reviewed "Canceled". Test: CtsLibcoreTestCases Test: CtsLibcoreOkHttpTestCases Bug: 33763156 Change-Id: Ie8e80559f9364cbd0a01c54b441fc10402b37862
-rw-r--r--okhttp/src/main/java/com/squareup/okhttp/internal/http/StreamAllocation.java4
1 files changed, 4 insertions, 0 deletions
diff --git a/okhttp/src/main/java/com/squareup/okhttp/internal/http/StreamAllocation.java b/okhttp/src/main/java/com/squareup/okhttp/internal/http/StreamAllocation.java
index 7d95338..fd3f03f 100644
--- a/okhttp/src/main/java/com/squareup/okhttp/internal/http/StreamAllocation.java
+++ b/okhttp/src/main/java/com/squareup/okhttp/internal/http/StreamAllocation.java
@@ -314,6 +314,10 @@ public final class StreamAllocation {
}
public boolean recover(RouteException e) {
+ // Android-changed: Canceled StreamAllocations can never recover http://b/33763156
+ if (canceled) {
+ return false;
+ }
if (connection != null) {
connectionFailed(e.getLastConnectException());
}