Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #4491: adding a more explicit shutdown exception #4500

Merged
merged 1 commit into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### 6.3-SNAPSHOT

#### Bugs
* Fix #4491: added a more explicit shutdown exception for okhttp
* Fix #4534: Java Generator CLI default handling of skipGeneratedAnnotations
* Fix #4535: The shell command string will now have single quotes sanitized
* Fix #4547: preventing timing issues with leader election cancel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.fabric8.kubernetes.client.okhttp;

import io.fabric8.kubernetes.client.Config;
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 @@ -42,6 +43,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 @@ -242,22 +244,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