title: OkHttp connection leaks due to cloned client
body: <p>I'm working on an <a href="https://github.com/fabric8io/kubernetes-client/issues/1090" rel="nofollow noreferrer">issue</a> related to Okhttp connection leaks. The leak stack trace seems to pointing to this WebSocket connection being opened in <a href="https://github.com/fabric8io/kubernetes-client/blob/master/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/PodOperationsImpl.java" rel="nofollow noreferrer">PodOperationsImpl</a>#L267:</p>
  
  <pre><code>        try {
              URL url = new URL(URLUtils.join(getResourceUrl().toString(), sb.toString()));
              Request.Builder r = new Request.Builder().url(url).header("Sec-WebSocket-Protocol", "v4.channel.k8s.io").get();
              OkHttpClient clone = client.newBuilder().readTimeout(0, TimeUnit.MILLISECONDS).build();
              final ExecWebSocketListener execWebSocketListener = new ExecWebSocketListener(getConfig(), in, out, err, errChannel, inPipe, outPipe, errPipe, errChannelPipe, execListener);
              clone.newWebSocket(r.build(), execWebSocketListener);
              execWebSocketListener.waitUntilReady();
              return execWebSocketListener;
          } catch (Throwable t) {
              throw KubernetesClientException.launderThrowable(forOperationType("exec"), t);
          }
  </code></pre>
  
  <p>When I run the test provided in the issue itself, I see connection leak messages on logs:</p>
  
  <pre><code>WARNING: A connection to http://localhost:48271/ was leaked. Did you forget to close a response body?
  java.lang.Throwable: response.body().close()
  </code></pre>
  
  <p>But when I create OkHttpClient from a new instance instead of cloning it from the previous one, these connection leak warnings are reduced by 3/4th. Is cloning client prone to connection leaks? Or whether I'm not doing it the right way? Is there any way to ensure if we can handle these connection leak warning messages?</p>
  
  <p>One more thing, the websocket is opened using <a href="https://github.com/fabric8io/kubernetes-client/blob/master/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ExecWebSocketListener.java" rel="nofollow noreferrer">ExecWebSocketListener</a>, which already implements <code>AutoCloseable</code>. Although doing try-with-resources from caller does seem to avoid these warnings. But I'm not sure whether it's actually fixing the root cause of leaks.</p>