Skip to content

Commit

Permalink
Add SocketTimeoutException as endpoint auto-disabling cause (RedHatIn…
Browse files Browse the repository at this point in the history
…sights#2726)


Co-authored-by: Gwenneg Lepage <[email protected]>
  • Loading branch information
g-duval and gwenneg authored May 29, 2024
1 parent a242e1b commit bf7332c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.redhat.cloud.notifications.connector.http;

public enum HttpErrorType {
SOCKET_TIMEOUT,
CONNECT_TIMEOUT,
CONNECTION_REFUSED,
HTTP_4XX,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.jboss.logging.Logger;

import javax.net.ssl.SSLHandshakeException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;

import static com.redhat.cloud.notifications.connector.http.ExchangeProperty.HTTP_ERROR_TYPE;
Expand All @@ -19,6 +20,7 @@
import static com.redhat.cloud.notifications.connector.http.HttpErrorType.CONNECT_TIMEOUT;
import static com.redhat.cloud.notifications.connector.http.HttpErrorType.HTTP_4XX;
import static com.redhat.cloud.notifications.connector.http.HttpErrorType.HTTP_5XX;
import static com.redhat.cloud.notifications.connector.http.HttpErrorType.SOCKET_TIMEOUT;
import static com.redhat.cloud.notifications.connector.http.HttpErrorType.SSL_HANDSHAKE;
import static com.redhat.cloud.notifications.connector.http.HttpErrorType.UNKNOWN_HOST;
import static org.apache.http.HttpStatus.SC_TOO_MANY_REQUESTS;
Expand Down Expand Up @@ -55,6 +57,12 @@ protected void process(Throwable t, Exchange exchange) {
} else {
logDefault(t, exchange);
}
} else if (t instanceof SocketTimeoutException) {
if (connectorConfig.isDisableFaultyEndpoints()) {
exchange.setProperty(HTTP_ERROR_TYPE, SOCKET_TIMEOUT);
} else {
logDefault(t, exchange);
}
} else if (t instanceof HttpHostConnectException) {
if (connectorConfig.isDisableFaultyEndpoints()) {
exchange.setProperty(HTTP_ERROR_TYPE, CONNECTION_REFUSED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
import static com.redhat.cloud.notifications.events.HttpErrorType.CONNECT_TIMEOUT;
import static com.redhat.cloud.notifications.events.HttpErrorType.HTTP_4XX;
import static com.redhat.cloud.notifications.events.HttpErrorType.HTTP_5XX;
import static com.redhat.cloud.notifications.events.HttpErrorType.SOCKET_TIMEOUT;
import static com.redhat.cloud.notifications.events.HttpErrorType.SSL_HANDSHAKE;
import static com.redhat.cloud.notifications.events.HttpErrorType.UNKNOWN_HOST;

@ApplicationScoped
public class EndpointErrorFromConnectorHelper {

private static final Set<HttpErrorType> HTTP_SERVER_ERRORS = Set.of(CONNECT_TIMEOUT, CONNECTION_REFUSED, HTTP_5XX, SSL_HANDSHAKE, UNKNOWN_HOST);
private static final Set<HttpErrorType> HTTP_SERVER_ERRORS = Set.of(SOCKET_TIMEOUT, CONNECT_TIMEOUT, CONNECTION_REFUSED, HTTP_5XX, SSL_HANDSHAKE, UNKNOWN_HOST);

@Inject
EndpointRepository endpointRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.redhat.cloud.notifications.events;

public enum HttpErrorType {
SOCKET_TIMEOUT("a timeout happened while waiting for the HTTP server response"),
CONNECT_TIMEOUT("a timeout happened while connecting to the HTTP server"),
CONNECTION_REFUSED("the connection to the HTTP server was refused"),
HTTP_4XX(""), // Message not used.
Expand Down

0 comments on commit bf7332c

Please sign in to comment.