Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7e6ba2e

Browse files
committed
fix ConnectException handling
1 parent e4462ab commit 7e6ba2e

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

‎http/src/main/java/com/arangodb/http/HttpCommunication.java‎

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
import java.io.Closeable;
4141
import java.io.IOException;
42+
import java.net.ConnectException;
4243
import java.net.SocketTimeoutException;
4344
import java.util.concurrent.CompletableFuture;
4445
import java.util.concurrent.CompletionException;
@@ -90,27 +91,10 @@ private CompletableFuture<InternalResponse> executeAsync(final InternalRequest r
9091
rfuture.completeExceptionally(new ArangoDBException(te, reqId));
9192
} else if (e instanceof TimeoutException) {
9293
rfuture.completeExceptionally(new ArangoDBException(e, reqId));
94+
} else if (e instanceof ConnectException) {
95+
handleException(true, e, hostHandle, request, host, reqId, attemptCount, rfuture);
9396
} 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);
11498
} else {
11599
if (LOGGER.isDebugEnabled()) {
116100
String body = response.getBody() == null ? "" : serde.toJsonString(response.getBody());
@@ -144,6 +128,29 @@ private CompletableFuture<InternalResponse> executeAsync(final InternalRequest r
144128
return rfuture;
145129
}
146130

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+
147154
private void mirror(CompletableFuture<InternalResponse> up, CompletableFuture<InternalResponse> down) {
148155
up.whenComplete((v, err) -> {
149156
if (err != null) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /