Skip to content

Commit e865f94

Browse files
author
adriancole
committed
Correctly handle IOExceptions wrapped by Ribbon.
1 parent ef2a6b9 commit e865f94

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
### Version 5.1.0
2+
* Correctly handle IOExceptions wrapped by Ribbon.
23
* Miscellaneous findbugs fixes.
34

45
### Version 5.0.1

ribbon/src/main/java/feign/ribbon/RibbonModule.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public RibbonClient(@Named("delegate") Client delegate) {
7676
LBClient.RibbonRequest ribbonRequest = new LBClient.RibbonRequest(request, uriWithoutSchemeAndPort);
7777
return lbClient(clientName).executeWithLoadBalancer(ribbonRequest).toResponse();
7878
} catch (ClientException e) {
79+
if (e.getCause() instanceof IOException) {
80+
throw IOException.class.cast(e.getCause());
81+
}
7982
throw Throwables.propagate(e);
8083
}
8184
}

ribbon/src/test/java/feign/ribbon/RibbonClientTest.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import com.google.mockwebserver.MockResponse;
1919
import com.google.mockwebserver.MockWebServer;
20+
import com.google.mockwebserver.SocketPolicy;
2021
import dagger.Provides;
2122
import feign.Feign;
2223
import feign.RequestLine;
@@ -36,7 +37,7 @@ public class RibbonClientTest {
3637
interface TestInterface {
3738
@RequestLine("POST /") void post();
3839

39-
@dagger.Module(injects = Feign.class, addsTo = Feign.Defaults.class)
40+
@dagger.Module(injects = Feign.class, overrides = true, addsTo = Feign.Defaults.class)
4041
static class Module {
4142
@Provides Decoder defaultDecoder() {
4243
return new Decoder.Default();
@@ -80,6 +81,33 @@ public void loadBalancingDefaultPolicyRoundRobin() throws IOException, Interrupt
8081
}
8182
}
8283

84+
@Test
85+
public void ioExceptionRetry() throws IOException, InterruptedException {
86+
String client = "RibbonClientTest-ioExceptionRetry";
87+
String serverListKey = client + ".ribbon.listOfServers";
88+
89+
MockWebServer server = new MockWebServer();
90+
server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.DISCONNECT_AT_START));
91+
server.enqueue(new MockResponse().setBody("success!".getBytes(UTF_8)));
92+
server.play();
93+
94+
getConfigInstance().setProperty(serverListKey, hostAndPort(server.getUrl("")));
95+
96+
try {
97+
98+
TestInterface api = Feign.create(TestInterface.class, "http://" + client, new TestInterface.Module(), new RibbonModule());
99+
100+
api.post();
101+
102+
assertEquals(server.getRequestCount(), 2);
103+
// TODO: verify ribbon stats match
104+
// assertEquals(target.lb().getLoadBalancerStats().getSingleServerStat())
105+
} finally {
106+
server.shutdown();
107+
getConfigInstance().clearProperty(serverListKey);
108+
}
109+
}
110+
83111
static String hostAndPort(URL url) {
84112
// our build slaves have underscores in their hostnames which aren't permitted by ribbon
85113
return "localhost:" + url.getPort();

0 commit comments

Comments
 (0)