Connection still alive with a dead proxy until restart

Viewed 62

I am developing a spring boot app where i have to call an API REST published by an other company. Here is the architecture :

              +--> P1 --->               +--> App1
T <---> LB1 <--+           +---> LB2 <---+  
              +--> P2 --->               +--> App2
  • T = My application (Tomcat J2E 11 --- spring boot : 2.2.2.RELEASE) --> Call the API
  • LB1 = Load balancer of reverse proxy - kubernete
  • P1/P2 = Reverse proxy
  • LB2 = Load balancer of applications - kubernete
  • App1/App2 = Application (whose API i'm calling)

My tomcat seems to be stuck with one of the proxy. When one of the reverse proxies dies, my tomcat doesn't automatically close the connection and open a new one to another proxy in the pool. Instead, my applications gets an error stating the the connection fails until restart.

If i run a new tomcat with spring boot and a similar code, when they kill the proxy it's seems to work fine. I can't see any big configuration change.

Here 's some code that i tryed :

Lib : HttpURLConnection

 try {
    URL url = new URL(EnvProperties.getString("ws.***.rapport") + idRapport);

    HttpURLConnection conn = null;
    FileOutputStream outputStream = null;
    InputStream inputStream = null;
    try {
        conn = (HttpURLConnection) url.openConnection();
        conn.setRequestProperty("Authorization", token***);
        conn.setRequestMethod("GET");
        conn.setRequestProperty("Connection", "close");
        if (conn.getResponseCode() != 200) {
            LOGGER.debug("[***Service-getDernierRapport] header " + conn.getHeaderFields().toString());
            throw new RuntimeException("Failed : HTTP Error code : " + conn.getResponseCode());
        }
        LOGGER.debug("[***Service-getDernierRapport] header " + conn.getHeaderFields().toString());
        //gestion de la réponse
    } finally {
        if (conn != null) {
            try {
                conn.disconnect();
            } catch (Exception ex) {
                // ignore ... any significant errors should already have been
                // reported via an IOException from the final flush.
            }
        }
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (Exception ex) {
                // ignore ... any significant errors should already have been
                // reported via an IOException from the final flush.
            }
        }
        if (outputStream != null) {
            try {
                outputStream.close();
            } catch (Exception ex) {
                // ignore ... any significant errors should already have been
                // reported via an IOException from the final flush.
            }
        }
    }

} catch (Exception e) {
    LOGGER.error("[***Service--getDernierRapport] Exception :- ", e);
    throw new NotFoundException();
}

Lib : HTTPClient

        URI uri = URI.create(EnvProperties.getString("ws.**.rapport") + idRapport);
        String saveFilePath = EnvProperties.getString("**.repertoire.rapports") + "/rapport_" + idRapport + ".pdf";
        try {
            HttpClient client = HttpClient.newHttpClient();
            HttpRequest request = HttpRequest.newBuilder().uri(uri).header("Authorization", token).build();

            HttpResponse<Path> response = client.send(request, BodyHandlers.ofFile(Paths.get(saveFilePath)));
            LOGGER.debug("[***Service--getDernierRapport] Resultat appel *** : " + response.statusCode());
            if (response.statusCode() != 200) {
                throw new RuntimeException("Failed : HTTP Error code : " + response.statusCode());
            }

        } catch (Exception e) {
            LOGGER.error("[***Service--getDernierRapport] Exception :- ", e);
            throw new NotFoundException();
        }

Do you see what can keep the connection alive with the proxy behind the LB1?

0 Answers
Related