<p>I'm getting a <code>java.net.SocketException: Socket closed</code> exception with the <a href="https://github.com/fabric8io/kubernetes-client" rel="nofollow noreferrer">fabric8 kubernerties client</a> version 4.10.2 and <a href="https://github.com/fabric8io/kubernetes-client/blob/master/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/Watcher.java" rel="nofollow noreferrer">Watcher</a>.</p>
<p>The code looks like:</p>
<pre><code>KubernetesClient client = createClient();
client.pods().watch(createLogWatcher(&quot;pod&quot;));
client.apps().deployments().watch(createLogWatcher(&quot;deployment&quot;));
client.services().watch(createLogWatcher(&quot;service&quot;));
client.extensions().ingresses().watch(createLogWatcher(&quot;ingress&quot;));

// do stuff with client
</code></pre>
<p>And I get the following exception <strong>as my application is shutting down</strong></p>
<pre><code>08:10:37.180 [OkHttp https://test-api.ib.dnsbego.de:6443/...] WARN  i.f.k.c.d.i.WatchConnectionManager - Exec Failure
javax.net.ssl.SSLException: Socket closed
    at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:127)
    at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:320)
    at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:263)
    at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:258)
    at java.base/sun.security.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1315)
    at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:839)
    at okio.Okio$2.read(Okio.java:140)
    at okio.AsyncTimeout$2.read(AsyncTimeout.java:237)
    at okio.RealBufferedSource.request(RealBufferedSource.java:72)
    at okio.RealBufferedSource.require(RealBufferedSource.java:65)
    at okio.RealBufferedSource.readByte(RealBufferedSource.java:78)
    at okhttp3.internal.ws.WebSocketReader.readHeader(WebSocketReader.java:117)
    at okhttp3.internal.ws.WebSocketReader.processNextFrame(WebSocketReader.java:101)
    at okhttp3.internal.ws.RealWebSocket.loopReader(RealWebSocket.java:273)
    at okhttp3.internal.ws.RealWebSocket$1.onResponse(RealWebSocket.java:209)
    at okhttp3.RealCall$AsyncCall.execute(RealCall.java:174)
    at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:834)
    Suppressed: java.net.SocketException: Socket closed
        at java.base/java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)
        at java.base/java.net.SocketOutputStream.write(SocketOutputStream.java:150)
        at java.base/sun.security.ssl.SSLSocketOutputRecord.encodeAlert(SSLSocketOutputRecord.java:81)
        at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:351)
        ... 18 common frames omitted
Caused by: java.net.SocketException: Socket closed
    at java.base/java.net.SocketInputStream.socketRead0(Native Method)
    at java.base/java.net.SocketInputStream.socketRead(SocketInputStream.java:115)
    at java.base/java.net.SocketInputStream.read(SocketInputStream.java:168)
    at java.base/java.net.SocketInputStream.read(SocketInputStream.java:140)
    at java.base/sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:448)
    at java.base/sun.security.ssl.SSLSocketInputRecord.bytesInCompletePacket(SSLSocketInputRecord.java:68)
    at java.base/sun.security.ssl.SSLSocketImpl.readApplicationRecord(SSLSocketImpl.java:1104)
    at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:823)
    ... 14 common frames omitted
</code></pre>

<p>I figured this out myself but thought I'd post for the next person since I couldn't find any discussion on this.</p>
<p>Each <code>watcher(...)</code> call returns a <code>Watch</code> instance which can be closed so I solved this via:</p>
<pre><code>KubernetesClient client = createClient();
List&lt;Watch&gt; watches = new ArrayList&lt;&gt;();
watches.add(client.pods().watch(createLogWatcher(&quot;pod&quot;)));
watches.add(client.apps().deployments().watch(createLogWatcher(&quot;deployment&quot;)));
watches.add(client.services().watch(createLogWatcher(&quot;service&quot;)));
watches.add(client.extensions().ingresses().watch(createLogWatcher(&quot;ingress&quot;)));
try {
   // do stuff
} finally {
   watches.forEach(Watch::close);
}
</code></pre>
