kubernetes-client / java

Official Java client library for kubernetes
http://kubernetes.io/
Apache License 2.0
3.46k stars 1.85k forks source link

java.net.SocketException: Connection or outbound has been closed #3385

Open tporeba opened 2 months ago

tporeba commented 2 months ago

Describe the bug When doing more complex kubectl exec calls using the example code based on https://github.com/kubernetes-client/java/blob/master/examples/examples-release-latest/src/main/java/io/kubernetes/client/examples/ExecExample.java I am very often observing an exception

   java.net.SocketException: Connection or outbound has been closed
        at sun.security.ssl.SSLSocketOutputRecord.deliver(SSLSocketOutputRecord.java:267)
        at sun.security.ssl.SSLSocketImpl$AppOutputStream.write(SSLSocketImpl.java:1193)
        at okio.OutputStreamSink.write(JvmOkio.kt:56)
        at okio.AsyncTimeout$sink$1.write(AsyncTimeout.kt:102)
        at okio.RealBufferedSink.flush(RealBufferedSink.kt:268)
        at okhttp3.internal.ws.WebSocketWriter.writeControlFrame(WebSocketWriter.kt:142)
        at okhttp3.internal.ws.WebSocketWriter.writeClose(WebSocketWriter.kt:102)
        at okhttp3.internal.ws.RealWebSocket.writeOneFrame$okhttp(RealWebSocket.kt:533)
        at okhttp3.internal.ws.RealWebSocket$WriterTask.runOnce(RealWebSocket.kt:620)
        at okhttp3.internal.concurrent.TaskRunner.runTask(TaskRunner.kt:116)
        at okhttp3.internal.concurrent.TaskRunner.access$runTask(TaskRunner.kt:42)
        at okhttp3.internal.concurrent.TaskRunner$runnable$1.run(TaskRunner.kt:65)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:750)

It still works, it doesn't break the call, but it is very annoying and unnecessarily attracts attention when looking at the logs from the tool.

Client Version 20.0.0

Kubernetes Version e.g. 1.26.5

Java Version Java 8

To Reproduce Steps to reproduce the behavior: Run the code from https://github.com/kubernetes-client/java/blob/master/examples/examples-release-latest/src/main/java/io/kubernetes/client/examples/ExecExample.java couple of times.

Expected behavior Exception should not be thrown.

Additional context This was already reported in https://github.com/kubernetes-client/java/issues/1891 , https://github.com/kubernetes-client/java/issues/1923 but wasn't fixed. Maybe this time?

brendandburns commented 2 months ago

I think that you need to set the unhandled exception handler here:

https://github.com/kubernetes-client/java/blob/master/util/src/main/java/io/kubernetes/client/Exec.java#L110

And if you do that, you should be able to supress this logging.