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 a48455f
Showing 1 changed file with 13 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,17 @@ void release() {

if (client instanceof AutoCloseable) {
try {
// The HttpClient::close may hang during the termination.
try {
// Try to call shutdownNow() first
MethodHandles.publicLookup()
.findVirtual(HttpClient.class, "shutdownNow", MethodType.methodType(void.class))
.bindTo(client)
.invokeExact();
} catch (final Throwable e) {
//ignore
}

((AutoCloseable)client).close();
} catch (Exception e) {
//ignore
Expand Down

0 comments on commit a48455f

Please sign in to comment.