Skip to content

PodLogs is not closing Response on error #2310

@adamjshook

Description

@adamjshook

Describe the bug

The A connection to https://foo.com:6443/ was leaked. Did you forget to close a response body? issue has been reported a few times before but not with enough information. The two stack traces in the Additional Context section below shows the initial request to stream the pod log with a 404 error, then later on we get the error message from OkHttpClient that it was leaked with the stack trace that shows where the request was created.

From the PodLogs source (linking the latest tag), the response is not closed prior to throwing the exception which would result in a leak. Users are unable to close this response.

Client Version 12.0.2

Kubernetes Version 1.20.11

Java Version JDK 11.0.2

To Reproduce

  1. Request to stream logs from a pod that does not exist getting a 404
  2. See log where connection is leaked later on

Expected behavior

The response body should be closed on error conditions so prevent leaking the client.

KubeConfig N/A

Server:

  • OS: Linux
  • Environment: Unknown
  • Cloud: N/A

Additional context N/A

Logs request failed: 404
io.kubernetes.client.openapi.ApiException: Logs request failed: 404
	at io.kubernetes.client.PodLogs.streamNamespacedPodLog(PodLogs.java:98)
	at io.kubernetes.client.PodLogs.streamNamespacedPodLog(PodLogs.java:70)
	at io.kubernetes.client.PodLogs.streamNamespacedPodLog(PodLogs.java:61)
	at x.y.z.ClientWrapper.retrievePodLog(ClientWrapper.java:456)

okhttp3.OkHttpClient: A connection to https://foo.com:6443/ was leaked. Did you forget to close a response body?
java.lang.Throwable: response.body().close()
	at okhttp3.internal.platform.Platform.getStackTraceForCloseable(Platform.java:149)
	at okhttp3.internal.connection.Transmitter.callStart(Transmitter.java:116)
	at okhttp3.RealCall.execute(RealCall.java:78)
	at io.kubernetes.client.PodLogs.streamNamespacedPodLog(PodLogs.java:96)
	at io.kubernetes.client.PodLogs.streamNamespacedPodLog(PodLogs.java:70)
	at io.kubernetes.client.PodLogs.streamNamespacedPodLog(PodLogs.java:61)
	at x.y.z.ClientWrapper.retrievePodLog(ClientWrapper.java:456)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions