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 26982def6d2..82bad1fa40d 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 @@ -47,9 +47,12 @@ import okio.BufferedSource; import okio.Okio; import okio.Source; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.BufferedInputStream; import java.io.IOException; +import java.io.InterruptedIOException; import java.io.Reader; import java.net.MalformedURLException; import java.nio.ByteBuffer; @@ -65,6 +68,8 @@ public class OkHttpClientImpl extends StandardHttpClient { + static final transient Logger LOG = LoggerFactory.getLogger(OkHttpClientImpl.class); + static final Map MEDIA_TYPES = new ConcurrentHashMap<>(); public static final MediaType JSON = parseMediaType("application/json"); @@ -235,6 +240,7 @@ public OkHttpClientImpl(OkHttpClient client, OkHttpClientBuilderImpl builder) { @Override public void close() { + LOG.debug("Shutting down dispatcher " + this.httpClient.dispatcher(), new Exception()); ConnectionPool connectionPool = httpClient.connectionPool(); Dispatcher dispatcher = httpClient.dispatcher(); ExecutorService executorService = httpClient.dispatcher() != null ? httpClient.dispatcher().executorService() : null; @@ -270,13 +276,15 @@ public void onResponse(Call call, Response response) throws IOException { @Override public void onFailure(Call call, IOException e) { - future.completeExceptionally(e); + Throwable t = e; + if (e instanceof InterruptedIOException && e.getCause() instanceof RejectedExecutionException) { + t = wrapRejected((RejectedExecutionException) e.getCause()); + } + future.completeExceptionally(t); } }); } catch (RejectedExecutionException e) { - throw new KubernetesClientException("The okhttp client executor has been shutdown. " - + "More than likely this is because the KubernetesClient.close method has been called " - + "- please ensure that is intentional.", e); + throw wrapRejected(e); } future.whenComplete((r, t) -> { if (future.isCancelled()) { @@ -286,6 +294,12 @@ public void onFailure(Call call, IOException e) { return future; } + private KubernetesClientException wrapRejected(RejectedExecutionException e) { + return new KubernetesClientException("The okhttp client executor has been shutdown. " + + "More than likely this is because the KubernetesClient.close method (see debug logging) has been called " + + "- please ensure that is intentional. Dispatcher: " + this.httpClient.dispatcher(), e); + } + public okhttp3.OkHttpClient getOkHttpClient() { return httpClient; }