Skip to content

Commit

Permalink
fix fabric8io#4491: adding a more explicit shutdown exception
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Oct 14, 2022
1 parent 177de1c commit 6a3ccac
Showing 1 changed file with 20 additions and 12 deletions.
Expand Up @@ -16,6 +16,7 @@

package io.fabric8.kubernetes.client.okhttp;

import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.client.http.HttpClient;
import io.fabric8.kubernetes.client.http.HttpRequest;
import io.fabric8.kubernetes.client.http.HttpResponse;
Expand All @@ -40,6 +41,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.RejectedExecutionException;
import java.util.function.Function;

public class OkHttpClientImpl implements HttpClient {
Expand Down Expand Up @@ -238,22 +240,28 @@ private CompletableFuture<HttpResponse<AsyncBody>> sendAsync(HttpRequest request
Function<BufferedSource, AsyncBody> handler) {
CompletableFuture<HttpResponse<AsyncBody>> future = new CompletableFuture<>();
Call call = httpClient.newCall(((OkHttpRequestImpl) request).getRequest());
call.enqueue(new Callback() {
try {
call.enqueue(new Callback() {

@Override
public void onResponse(Call call, Response response) throws IOException {
BufferedSource source = response.body().source();
@Override
public void onResponse(Call call, Response response) throws IOException {
BufferedSource source = response.body().source();

AsyncBody asyncBody = handler.apply(source);
AsyncBody asyncBody = handler.apply(source);

future.complete(new OkHttpResponseImpl<>(response, asyncBody));
}
future.complete(new OkHttpResponseImpl<>(response, asyncBody));
}

@Override
public void onFailure(Call call, IOException e) {
future.completeExceptionally(e);
}
});
@Override
public void onFailure(Call call, IOException e) {
future.completeExceptionally(e);
}
});
} 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);
}
future.whenComplete((r, t) -> {
if (future.isCancelled()) {
call.cancel();
Expand Down

0 comments on commit 6a3ccac

Please sign in to comment.