java icon indicating copy to clipboard operation
java copied to clipboard

java.net.SocketTimeoutException when applyManifest to private cluster using OkHttpClient with dns

Open chenqia2 opened this issue 8 months ago • 3 comments
trafficstars

Describe the bug After we upgraded our k8s java client version from 18.0.1 to 20.0.0, we start seeing java.net.SocketTimeoutException when applyManifest to private cluster using OkHttpClient with dns. The same code has no issue for version 18.0.1, has same issue for version 20.0.0 and 23.0.0. our code is: ` private ApiClient buildApiClient(final KubeConfigToken kubeConfigToken) { ApiClient apiClient = newApiClient(kubeConfigToken); if (kubeConfigToken.getIsPrivateAccessEnabled()) { OkHttpClient httpClient = okHttpClientwithDns(apiClient.getHttpClient().newBuilder(), kubeConfigToken); apiClient.setHttpClient(httpClient); } return apiClient; }

public OkHttpClient okHttpClientwithDns(OkHttpClient.Builder apiClientBuilder, KubeConfigToken kubeConfigToken) { String dnsProxyIp = "dns://" + kubeConfigToken.getDnsProxyIp(); List<String> hostNames = prepareHostNames(kubeConfigToken); return apiClientBuilder .dns(new CustomDns(dnsProxyIp, hostNames)) .build(); }when we are using this client as shown below:Class clazz = resource.getClass(); KubectlApply kubectlApply = (KubectlApply) Kubectl.apply(clazz).fieldManager("kubectl") .forceConflict(true).resource((KubernetesObject) resource).namespace(namespace); KubectlApply kubectlApplyClient; kubectlApplyClient = (KubectlApply) kubectlApply.apiClient(apiClient); kubectlApplyClient = (KubectlApply) kubectlApplyClient.skipDiscovery(); ModelMapper.refresh(newDiscovery(kubeConfigToken), Duration.ZERO); we got SocketTimeoutException with stack trace:Unable to invoke apply command for resource: helloworld of kind: Deployment in namespace: default: io.kubernetes.client.openapi.ApiException: Message: java.net.SocketTimeoutException: Connect timed out HTTP response code: 0 HTTP response body: null HTTP response headers: null at io.kubernetes.client.openapi.ApiClient.execute(ApiClient.java:1032) at io.kubernetes.client.Discovery.get(Discovery.java:192) at io.kubernetes.client.Discovery.versionDiscovery(Discovery.java:169) at io.kubernetes.client.Discovery.legacyCoreApi(Discovery.java:161) at io.kubernetes.client.Discovery.findAll(Discovery.java:51) at io.kubernetes.client.util.ModelMapper.refresh(ModelMapper.java:273)`

Our observation is that this issue only happens for OkHttpClient with dns being set. there is no such issue when we use it for our public cluster, which doesn't need

Client Version both 20.0.0 and 23.0.0 have this issue

Kubernetes Version 1.31.0 and 1.30.0

Java Version Java 17

To Reproduce Steps to reproduce the behavior:

  1. create an OkHttpClient with custom dns being set
  2. create an ApiClient with setHttpClient from step 1
  3. use the client from setp2 to apply manifest file. Expected behavior no exception, the manifest will be applied.

KubeConfig If applicable, add a KubeConfig file with secrets redacted.

Server (please complete the following information):

  • OS: [e.g. Linux]
  • Environment [e.g. container]
  • Cloud [e.g. Azure]

Additional context Add any other context about the problem here.

chenqia2 avatar Mar 11 '25 17:03 chenqia2

@brendandburns would appreciated if you can take a look, thanks

chenqia2 avatar Mar 11 '25 17:03 chenqia2

My guess is that between 18 and 20 the version of the OkHTTP library changed and there is some difference/bug in that library.

I don't have a cluster that requires custom DNS so it is hard for me to reproduce this and given that it works when you don't specify DNS, it seems to be a problem in OkHTTP, not this client.

brendandburns avatar Mar 12 '25 14:03 brendandburns

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Jun 10 '25 15:06 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle rotten
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

k8s-triage-robot avatar Jul 10 '25 15:07 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

k8s-triage-robot avatar Aug 09 '25 16:08 k8s-triage-robot

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

k8s-ci-robot avatar Aug 09 '25 16:08 k8s-ci-robot