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
  • Loading branch information
reta committed May 8, 2024
1 parent c56b1f1 commit dd17da9
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
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,27 @@ void release() {

if (client instanceof AutoCloseable) {
try {
// The HttpClient::close may hang during the termination.
try {
// Try to call shutdownNow() first
AccessController.doPrivileged((PrivilegedExceptionAction<?>) () -> {
try {
return MethodHandles.publicLookup()
.findVirtual(HttpClient.class, "shutdownNow", MethodType.methodType(void.class))
.bindTo(client)
.invokeExact();
} 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 dd17da9

Please sign in to comment.