1
0
mirror of https://github.com/square/okhttp.git synced 2026-01-14 07:22:20 +03:00

Short circuit more aggressively when ExchangeFinder has routes.

This commit is contained in:
Dave Roberge
2020-03-26 10:00:21 -05:00
parent e8cfef759f
commit 08489df02e
2 changed files with 10 additions and 4 deletions

View File

@@ -124,11 +124,15 @@ class ExchangeFinder(
// Make sure we have some routes left to try. One example where we may exhaust all the routes
// would happen if we made a new connection and it immediately is detected as unhealthy.
synchronized(connectionPool) {
if (nextRouteToTry != null) return@synchronized
val routesLeft = routeSelection?.hasNext() ?: true
if (routesLeft) return@synchronized
val routesSelectionLeft = routeSelector?.hasNext() ?: true
if (nextRouteToTry == null && !routesLeft && !routesSelectionLeft) {
throw IOException("exhausted all routes")
}
if (routesSelectionLeft) return@synchronized
throw IOException("exhausted all routes")
}
}
}

View File

@@ -3804,7 +3804,9 @@ public final class CallTest {
.eventListener(listener)
.build();
executeSynchronously("/").assertFailure(IOException.class);
executeSynchronously("/")
.assertFailure(IOException.class)
.assertFailure("exhausted all routes");
}
@Test public void requestBodyThrowsUnrelatedToNetwork() throws Exception {