Skip to content

Commit

Permalink
CXF-8987: JDK 21+: HttpClientHTTPConduit thread locked during shutdown (
Browse files Browse the repository at this point in the history
#1854)

(cherry picked from commit efa1716)
  • Loading branch information
reta committed May 11, 2024
1 parent 645d5b4 commit 54e2f75
Showing 1 changed file with 24 additions and 0 deletions.
Expand Up @@ -25,6 +25,8 @@
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;
Expand Down Expand Up @@ -129,6 +131,28 @@ void release() {

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
Expand Down

0 comments on commit 54e2f75

Please sign in to comment.