This is an automated email from the ASF dual-hosted git repository. reta pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/main by this push: new efa1716a5c CXF-8987: JDK 21+: HttpClientHTTPConduit thread locked during shutdown (#1854) efa1716a5c is described below commit efa1716a5c3ea70ef3f8c0527a1e05c6646c01b3 Author: Andriy Redko <drr...@gmail.com> AuthorDate: Sat May 11 07:44:44 2024 -0400 CXF-8987: JDK 21+: HttpClientHTTPConduit thread locked during shutdown (#1854) --- .../cxf/transport/http/HttpClientHTTPConduit.java | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HttpClientHTTPConduit.java b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HttpClientHTTPConduit.java index 4435bf01e8..6cc533931b 100644 --- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HttpClientHTTPConduit.java +++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HttpClientHTTPConduit.java @@ -25,6 +25,8 @@ import java.io.OutputStream; import java.io.PipedInputStream; import java.io.PipedOutputStream; import java.io.PushbackInputStream; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; import java.net.ConnectException; import java.net.HttpURLConnection; import java.net.MalformedURLException; @@ -129,6 +131,28 @@ public class HttpClientHTTPConduit extends URLConnectionHTTPConduit { if (client instanceof AutoCloseable) { try { + // The HttpClient::close may hang during the termination. + try { + // Try to call shutdownNow() first + AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> { + try { + MethodHandles.publicLookup() + .findVirtual(HttpClient.class, "shutdownNow", MethodType.methodType(void.class)) + .bindTo(client) + .invokeExact(); + return null; + } catch (final Throwable ex) { + if (ex instanceof Error) { + throw (Error) ex; + } else { + throw (Exception) ex; + } + } + }); + } catch (final PrivilegedActionException e) { + //ignore + } + ((AutoCloseable)client).close(); } catch (Exception e) { //ignore