title: Connection still alive with a dead proxy until restart
body: <p>I am developing a spring boot app where i have to call an API REST published by an other company.
  Here is the architecture :</p>
  <pre><code>              +--&gt; P1 ---&gt;               +--&gt; App1
  T &lt;---&gt; LB1 &lt;--+           +---&gt; LB2 &lt;---+  
                +--&gt; P2 ---&gt;               +--&gt; App2
  </code></pre>
  <ul>
  <li>T = My application (Tomcat J2E 11 --- spring boot : 2.2.2.RELEASE) --&gt; Call the API</li>
  <li>LB1 = Load balancer of reverse proxy - kubernete</li>
  <li>P1/P2 = Reverse proxy</li>
  <li>LB2 = Load balancer of applications - kubernete</li>
  <li>App1/App2 = Application (whose API i'm calling)</li>
  </ul>
  <p>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.</p>
  <p>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.</p>
  <p>Here 's some code that i tryed :</p>
  <p>Lib : HttpURLConnection</p>
  <pre><code> try {
      URL url = new URL(EnvProperties.getString(&quot;ws.***.rapport&quot;) + idRapport);
  
      HttpURLConnection conn = null;
      FileOutputStream outputStream = null;
      InputStream inputStream = null;
      try {
          conn = (HttpURLConnection) url.openConnection();
          conn.setRequestProperty(&quot;Authorization&quot;, token***);
          conn.setRequestMethod(&quot;GET&quot;);
          conn.setRequestProperty(&quot;Connection&quot;, &quot;close&quot;);
          if (conn.getResponseCode() != 200) {
              LOGGER.debug(&quot;[***Service-getDernierRapport] header &quot; + conn.getHeaderFields().toString());
              throw new RuntimeException(&quot;Failed : HTTP Error code : &quot; + conn.getResponseCode());
          }
          LOGGER.debug(&quot;[***Service-getDernierRapport] header &quot; + 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(&quot;[***Service--getDernierRapport] Exception :- &quot;, e);
      throw new NotFoundException();
  }
  
  </code></pre>
  <p>Lib : HTTPClient</p>
  <pre><code>        URI uri = URI.create(EnvProperties.getString(&quot;ws.**.rapport&quot;) + idRapport);
          String saveFilePath = EnvProperties.getString(&quot;**.repertoire.rapports&quot;) + &quot;/rapport_&quot; + idRapport + &quot;.pdf&quot;;
          try {
              HttpClient client = HttpClient.newHttpClient();
              HttpRequest request = HttpRequest.newBuilder().uri(uri).header(&quot;Authorization&quot;, token).build();
  
              HttpResponse&lt;Path&gt; response = client.send(request, BodyHandlers.ofFile(Paths.get(saveFilePath)));
              LOGGER.debug(&quot;[***Service--getDernierRapport] Resultat appel *** : &quot; + response.statusCode());
              if (response.statusCode() != 200) {
                  throw new RuntimeException(&quot;Failed : HTTP Error code : &quot; + response.statusCode());
              }
  
          } catch (Exception e) {
              LOGGER.error(&quot;[***Service--getDernierRapport] Exception :- &quot;, e);
              throw new NotFoundException();
          }
  </code></pre>
  <p>Do you see what can keep the connection alive with the proxy behind the LB1?</p>