|
39 | 39 |
|
40 | 40 | import java.io.Closeable;
|
41 | 41 | import java.io.IOException;
|
| 42 | +import java.net.ConnectException; |
42 | 43 | import java.net.SocketTimeoutException;
|
43 | 44 | import java.util.concurrent.CompletableFuture;
|
44 | 45 | import java.util.concurrent.CompletionException;
|
@@ -90,27 +91,10 @@ private CompletableFuture<InternalResponse> executeAsync(final InternalRequest r
|
90 | 91 | rfuture.completeExceptionally(new ArangoDBException(te, reqId));
|
91 | 92 | } else if (e instanceof TimeoutException) {
|
92 | 93 | rfuture.completeExceptionally(new ArangoDBException(e, reqId));
|
| 94 | + } else if (e instanceof ConnectException) { |
| 95 | + handleException(true, e, hostHandle, request, host, reqId, attemptCount, rfuture); |
93 | 96 | } else if (e != null) {
|
94 | | - IOException ioEx = wrapIOEx(e); |
95 | | - hostHandler.fail(ioEx); |
96 | | - if (hostHandle != null && hostHandle.getHost() != null) { |
97 | | - hostHandle.setHost(null); |
98 | | - } |
99 | | - |
100 | | - Host nextHost = hostHandler.get(hostHandle, RequestUtils.determineAccessType(request)); |
101 | | - if (nextHost != null && isSafe(request)) { |
102 | | - LOGGER.warn("Could not connect to {} while executing request [id={}]", |
103 | | - host.getDescription(), reqId, ioEx); |
104 | | - LOGGER.debug("Try connecting to {}", nextHost.getDescription()); |
105 | | - mirror( |
106 | | - executeAsync(request, hostHandle, nextHost, attemptCount), |
107 | | - rfuture |
108 | | - ); |
109 | | - } else { |
110 | | - ArangoDBException aEx = new ArangoDBException(ioEx, reqId); |
111 | | - LOGGER.error(aEx.getMessage(), aEx); |
112 | | - rfuture.completeExceptionally(aEx); |
113 | | - } |
| 97 | + handleException(isSafe(request), e, hostHandle, request, host, reqId, attemptCount, rfuture); |
114 | 98 | } else {
|
115 | 99 | if (LOGGER.isDebugEnabled()) {
|
116 | 100 | String body = response.getBody() == null ? "" : serde.toJsonString(response.getBody());
|
@@ -144,6 +128,29 @@ private CompletableFuture<InternalResponse> executeAsync(final InternalRequest r
|
144 | 128 | return rfuture;
|
145 | 129 | }
|
146 | 130 |
|
| 131 | + private void handleException(boolean isSafe, Throwable e, HostHandle hostHandle, InternalRequest request, Host host, |
| 132 | + long reqId, int attemptCount, CompletableFuture<InternalResponse> rfuture) { |
| 133 | + IOException ioEx = wrapIOEx(e); |
| 134 | + hostHandler.fail(ioEx); |
| 135 | + if (hostHandle != null && hostHandle.getHost() != null) { |
| 136 | + hostHandle.setHost(null); |
| 137 | + } |
| 138 | + Host nextHost = hostHandler.get(hostHandle, RequestUtils.determineAccessType(request)); |
| 139 | + if (nextHost != null && isSafe) { |
| 140 | + LOGGER.warn("Could not connect to {} while executing request [id={}]", |
| 141 | + host.getDescription(), reqId, ioEx); |
| 142 | + LOGGER.debug("Try connecting to {}", nextHost.getDescription()); |
| 143 | + mirror( |
| 144 | + executeAsync(request, hostHandle, nextHost, attemptCount), |
| 145 | + rfuture |
| 146 | + ); |
| 147 | + } else { |
| 148 | + ArangoDBException aEx = new ArangoDBException(ioEx, reqId); |
| 149 | + LOGGER.error(aEx.getMessage(), aEx); |
| 150 | + rfuture.completeExceptionally(aEx); |
| 151 | + } |
| 152 | + } |
| 153 | + |
147 | 154 | private void mirror(CompletableFuture<InternalResponse> up, CompletableFuture<InternalResponse> down) {
|
148 | 155 | up.whenComplete((v, err) -> {
|
149 | 156 | if (err != null) {
|
|
0 commit comments