From a613c0a0db9909b5176131ec2ecd3a2e81fe9c6d Mon Sep 17 00:00:00 2001 From: Steve Hawkins Date: Fri, 3 Jan 2025 12:35:55 -0500 Subject: [PATCH] fix: catching rejected execution closes: #6747 Signed-off-by: Steve Hawkins --- CHANGELOG.md | 2 ++ .../dsl/internal/ExecWebSocketListener.java | 29 +++++++++++-------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 943247c3263..4611fd5db5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ #### Bugs +* Fix #6747: Preventing websocket error logs when the client is closed + #### Improvements #### Dependency Upgrade diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ExecWebSocketListener.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ExecWebSocketListener.java index f10884c18ce..0eb8337996c 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ExecWebSocketListener.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ExecWebSocketListener.java @@ -47,6 +47,7 @@ import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; @@ -370,19 +371,23 @@ public void onClose(WebSocket webSocket, int code, String reason) { } closeWebSocketOnce(code, reason); LOGGER.debug("Exec Web Socket: On Close with code:[{}], due to: [{}]", code, reason); - serialExecutor.execute(() -> { - try { - if (exitCode.complete(null)) { - // this is expected for processes that don't terminate - uploads for example - LOGGER.debug("Exec Web Socket: completed with a null exit code - no status was received prior to onClose"); - } - cleanUpOnce(); - } finally { - if (listener != null) { - listener.onClose(code, reason); + try { + serialExecutor.execute(() -> { + try { + if (exitCode.complete(null)) { + // this is expected for processes that don't terminate - uploads for example + LOGGER.debug("Exec Web Socket: completed with a null exit code - no status was received prior to onClose"); + } + cleanUpOnce(); + } finally { + if (listener != null) { + listener.onClose(code, reason); + } } - } - }); + }); + } catch (RejectedExecutionException e) { + LOGGER.debug("Client already shutdown, aborting normal closure", e); + } } @Override