From b5c9a5c16f2cd077b8a84038210745fdc8c6506b Mon Sep 17 00:00:00 2001 From: Steven Hawkins Date: Fri, 20 Sep 2024 05:22:32 -0400 Subject: [PATCH] fix: moving source close to the executor (just like doConsume) close: #6354 Signed-off-by: Steve Hawkins --- CHANGELOG.md | 1 + .../fabric8/kubernetes/client/okhttp/OkHttpClientImpl.java | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8174d2a804a..39fa9c607a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ * Fix #6281: use GitHub binary repo for Kube API Tests * Fix #6282: Allow annotated types with Pattern, Min, and Max with Lists and Maps and CRD generation * Fix #5480: Move `io.fabric8:zjsonpatch` to KubernetesClient project +* Fix #6354: Prevent deadlock in okhttp AsyncBody.cancel #### Dependency Upgrade * Fix #6052: Removed dependency on no longer maintained com.github.mifmif:generex diff --git a/httpclient-okhttp/src/main/java/io/fabric8/kubernetes/client/okhttp/OkHttpClientImpl.java b/httpclient-okhttp/src/main/java/io/fabric8/kubernetes/client/okhttp/OkHttpClientImpl.java index 81a88396fef..a267630893d 100644 --- a/httpclient-okhttp/src/main/java/io/fabric8/kubernetes/client/okhttp/OkHttpClientImpl.java +++ b/httpclient-okhttp/src/main/java/io/fabric8/kubernetes/client/okhttp/OkHttpClientImpl.java @@ -151,7 +151,10 @@ public CompletableFuture done() { @Override public void cancel() { - Utils.closeQuietly(source); + // closing from a non dispatcher thread risks deadlock because close is + // a long-running operation that may need to re-obtain the dispatcher lock + // and the thread may already be holding other locks + executor.execute(() -> Utils.closeQuietly(source)); done.cancel(false); } }