Skip to content

Commit

Permalink
[SDCISA-13746] Increase resilience on resource exhaustion
Browse files Browse the repository at this point in the history
Related:
- [SDCISA-13746] Houston Exit Code 137
- [SDCISA-15051] Deployment FPD-Masterdaten nicht möglich
- [SDCISA-15053] Beeble: Deployement auf Masterdata funktioniert nicht
- [SDCISA-14025] Houston: Heap OOM and many FileHandles on Integration
- [SDCISA-10974] Houston: Storage request failed
- [SDCISA-13736] General ErrorHunting
  • Loading branch information
hiddenalpha committed Mar 8, 2024
1 parent f4de6da commit 8a43874
Showing 1 changed file with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import java.util.concurrent.TimeoutException;
import java.util.regex.Pattern;

import static java.lang.Long.parseLong;

/**
* Forwards requests to the backend.
*
Expand Down Expand Up @@ -239,31 +241,49 @@ private void handleRequest(final HttpServerRequest req, final Buffer bodyData, f
final LoggingHandler loggingHandler = new LoggingHandler(loggingResourceManager, logAppenderRepository, req, vertx.eventBus());

final String uniqueId = req.headers().get("x-rp-unique_id");
final String timeout = req.headers().get("x-timeout");
final String timeoutRaw = req.headers().get("x-timeout");
long timeoutMs = (timeoutRaw != null) ? parseLong(timeoutRaw) : rule.getTimeout();
final long startTime = monitoringHandler.startRequestMetricTracking(rule.getMetricName(), req.uri());

retryPerformRequest(req, bodyData, targetUri, log, profileHeaderMap, authHeader.orElse(null),

Check warning on line 248 in gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java

View check run for this annotation

Codecov / codecov/patch

gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java#L248

Added line #L248 was not covered by tests
afterHandler, loggingHandler, uniqueId, timeoutMs, startTime);
}

Check warning on line 250 in gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java

View check run for this annotation

Codecov / codecov/patch

gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java#L250

Added line #L250 was not covered by tests

private void retryPerformRequest(
HttpServerRequest req, Buffer bodyData, String targetUri, Logger log, Map<String, String> profileHeaderMap,
AuthHeader authHeader, @Nullable Handler<Void> afterHandler, LoggingHandler loggingHandler,
String uniqueId, long timeoutMs, long startTime
){
client.request(req.method(), port, rule.getHost(), targetUri, new Handler<>() {
@Override
public void handle(AsyncResult<HttpClientRequest> event) {
req.resume();

if (event.failed()) {
log.warn("Problem to request {}: {}", targetUri, event.cause());
Throwable ex = event.cause();
long postponeMs = 1000;
long remainingTimeMs = timeoutMs - postponeMs;

Check warning on line 265 in gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java

View check run for this annotation

Codecov / codecov/patch

gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java#L263-L265

Added lines #L263 - L265 were not covered by tests
if (remainingTimeMs > 0 && ex instanceof ConnectionPoolTooBusyException) {
log.debug("EAGAIN: No connection avail now for {}", targetUri, ex);
vertx.setTimer(postponeMs, nonsense -> {
retryPerformRequest(req, bodyData, targetUri, log, profileHeaderMap, authHeader,

Check warning on line 269 in gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java

View check run for this annotation

Codecov / codecov/patch

gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java#L267-L269

Added lines #L267 - L269 were not covered by tests
afterHandler, loggingHandler, uniqueId, remainingTimeMs, startTime);
});
return;

Check warning on line 272 in gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java

View check run for this annotation

Codecov / codecov/patch

gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java#L271-L272

Added lines #L271 - L272 were not covered by tests
}
log.warn("Problem to request {}", targetUri, ex);

Check warning on line 274 in gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java

View check run for this annotation

Codecov / codecov/patch

gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java#L274

Added line #L274 was not covered by tests
final HttpServerResponse response = req.response();
response.setStatusCode(StatusCode.SERVICE_UNAVAILABLE.getStatusCode());
response.setStatusMessage(StatusCode.SERVICE_UNAVAILABLE.getStatusMessage());
response.end();
return;
}

HttpClientRequest cReq = event.result();
final Handler<AsyncResult<HttpClientResponse>> cResHandler = getAsyncHttpClientResponseHandler(req, targetUri, log, profileHeaderMap, loggingHandler, startTime, afterHandler);
cReq.response(cResHandler);

if (timeout != null) {
cReq.idleTimeout(Long.parseLong(timeout));
} else {
cReq.idleTimeout(rule.getTimeout());
}
cReq.idleTimeout(timeoutMs);

Check warning on line 286 in gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java

View check run for this annotation

Codecov / codecov/patch

gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java#L286

Added line #L286 was not covered by tests

// per https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.10
MultiMap headersToForward = req.headers();
Expand All @@ -278,7 +298,7 @@ public void handle(AsyncResult<HttpClientRequest> event) {
}
setProfileHeaders(log, profileHeaderMap, cReq);

authHeader.ifPresent(authHeaderValue -> cReq.headers().set(authHeaderValue.key(), authHeaderValue.value()));
if (authHeader != null) cReq.headers().set(authHeader.key(), authHeader.value());

final String errorMessage = applyHeaderFunctions(log, cReq.headers());
if (errorMessage != null) {
Expand Down

0 comments on commit 8a43874

Please sign in to comment.