From 338206e8a7401f89101c7f779edc1adf097b0c7f Mon Sep 17 00:00:00 2001 From: "Wang, Fei" Date: Sun, 23 Mar 2025 13:19:22 -0700 Subject: [PATCH] [KYUUBI #6785] Shutdown the executor service in KubernetesApplicationOperation and prevent NPE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # :mag: Description ## Issue References ๐Ÿ”— As title. Fix NPE, because the cleanupTerminatedAppInfoTrigger will be set to `null`. https://github.com/apache/kyuubi/blob/d3520ddbcea96ec55c525600126047c44c7adb35/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala#L269 Also shutdown the ExecutorService when KubernetesApplicationOperation stoped. ## Describe Your Solution ๐Ÿ”ง Shutdown the thread executor service and check the null. ## Types of changes :bookmark: - [x] Bugfix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) ## Test Plan ๐Ÿงช #### Behavior Without This Pull Request :coffin: #### Behavior With This Pull Request :tada: #### Related Unit Tests --- # Checklist ๐Ÿ“ - [x] This patch was not authored or co-authored using [Generative Tooling](https://www.apache.org/legal/generative-tooling.html) **Be nice. Be informative.** Closes #6785 from turboFei/npe_k8s. Closes #6785 6afd052e6 [Wang, Fei] comments f0c3e3134 [Wang, Fei] prevent npe 9dffe0125 [Wang, Fei] shutdown Authored-by: Wang, Fei Signed-off-by: Wang, Fei --- .../KubernetesApplicationOperation.scala | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala index 74dc398f0..59faee486 100644 --- a/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala +++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/engine/KubernetesApplicationOperation.scala @@ -151,10 +151,12 @@ class KubernetesApplicationOperation extends ApplicationOperation with Logging { expireCleanUpTriggerCacheExecutor, () => { try { - cleanupTerminatedAppInfoTrigger.asMap().asScala.foreach { - case (key, _) => - // do get to trigger cache eviction - cleanupTerminatedAppInfoTrigger.getIfPresent(key) + Option(cleanupTerminatedAppInfoTrigger).foreach { trigger => + trigger.asMap().asScala.foreach { + case (key, _) => + // do get to trigger cache eviction + trigger.getIfPresent(key) + } } } catch { case NonFatal(e) => error("Failed to evict clean up terminated app cache", e) @@ -273,6 +275,16 @@ class KubernetesApplicationOperation extends ApplicationOperation with Logging { Utils.tryLogNonFatalError(client.close()) } kubernetesClients.clear() + + if (expireCleanUpTriggerCacheExecutor != null) { + ThreadUtils.shutdown(expireCleanUpTriggerCacheExecutor) + expireCleanUpTriggerCacheExecutor = null + } + + if (cleanupCanceledAppPodExecutor != null) { + ThreadUtils.shutdown(cleanupCanceledAppPodExecutor) + cleanupCanceledAppPodExecutor = null + } } private class SparkEnginePodEventHandler(kubernetesInfo: KubernetesInfo)