Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-8987

Java 21 - HttpClientHTTPConduit thread locked during shutdown

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Blocker
    • Resolution: Fixed
    • 4.0.3, 4.0.4
    • 4.1.0, 4.0.5, 3.6.4
    • Transports
    • None
    • Unknown

    Description

      Hi,

      I am using Apache CXF client via the Apache Camel CXF connector.

      After I updated frm OpenJDK 17.x to OpenJDK 21.0.2, during application shutdown, the following lock occurs:

      at java.lang.Thread.join(java.base@21.0.2/Thread.java:2072)
          - locked <0x000000061cd2ab80> (a jdk.internal.net.http.HttpClientImpl$SelectorManager)
          at java.lang.Thread.join(java.base@21.0.2/Thread.java:2200)
          at jdk.internal.net.http.HttpClientImpl.awaitTermination(java.net.http@21.0.2/HttpClientImpl.java:628)
          at java.net.http.HttpClient.close(java.net.http@21.0.2/HttpClient.java:900)
          at jdk.internal.net.http.HttpClientFacade.close(java.net.http@21.0.2/HttpClientFacade.java:192)
          at org.apache.cxf.transport.http.HttpClientHTTPConduit.close(HttpClientHTTPConduit.java:125)

      HttpClientHTTPConduit.close

      public void close() {
          if (client instanceof AutoCloseable) {
              try {
                  ((AutoCloseable)client).close();
              } catch (Exception e) {
                  //ignore
              }
          } else if (client != null) {
              String name = client.toString();
              client = null;
              tryToShutdownSelector(name);
          }
          defaultAddress = null;
          super.close();
      } 

       
      java.net.HttpClient.close
       

      public void close() {
          boolean terminated = isTerminated();
          if (!terminated) {
              shutdown();
              boolean interrupted = false;
              while (!terminated) {
                  try {
                      terminated = awaitTermination(Duration.ofDays(1L));
                  } catch (InterruptedException e) {
                      if (!interrupted) {
                          interrupted = true;
                          shutdownNow();
                          if (isTerminated()) break;
                      }
                  }
              }
              if (interrupted) {
                  Thread.currentThread().interrupt();
              }
          }
      } 

      My workaround

      public void close() {
          if (client instanceof AutoCloseable) {
              try {
                  client.shutdownNow();
                  //((AutoCloseable)client).close();
              } catch (Exception e) {
                  //ignore
              }
          } else if (client != null) {
              String name = client.toString();
              client = null;
              tryToShutdownSelector(name);
          }
          defaultAddress = null;
          super.close();
      } 

      Attachments

        1. thdump2
          39 kB
          Giacomo Carnevale

        Issue Links

          Activity

            People

              reta Andriy Redko
              carnevalegiacomo Giacomo Carnevale
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: