Skip to content

Commit

Permalink
adding more logging / detail about okhttp closure
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins authored and manusa committed Dec 5, 2022
1 parent 15639a7 commit 9b248dd
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -65,6 +68,8 @@

public class OkHttpClientImpl extends StandardHttpClient<OkHttpClientImpl, OkHttpClientFactory, OkHttpClientBuilderImpl> {

static final transient Logger LOG = LoggerFactory.getLogger(OkHttpClientImpl.class);

static final Map<String, MediaType> MEDIA_TYPES = new ConcurrentHashMap<>();

public static final MediaType JSON = parseMediaType("application/json");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand All @@ -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;
}
Expand Down

0 comments on commit 9b248dd

Please sign in to comment.