This is an automated email from the ASF dual-hosted git repository.

chengpan pushed a commit to branch branch-1.8
in repository https://gitbox.apache.org/repos/asf/kyuubi.git


The following commit(s) were added to refs/heads/branch-1.8 by this push:
     new 5f733a2a4 [KYUUBI #6410] Check if asyncRequestExecutor is initialized 
before shutdown
5f733a2a4 is described below

commit 5f733a2a43d99c207fc1f2f57810427806eab900
Author: wforget <[email protected]>
AuthorDate: Thu May 23 14:24:30 2024 +0800

    [KYUUBI #6410] Check if asyncRequestExecutor is initialized before shutdown
    
    # :mag: Description
    ## Issue References ๐Ÿ”—
    
    This pull request fixes #6410
    
    ## Describe Your Solution ๐Ÿ”ง
    
    Check if asyncRequestExecutor is initialized before shutdown to avoid NPE.
    
    ## 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 #6414 from wForget/KYUUBI-6410.
    
    Closes #6410
    
    1b7d35efe [wforget] comment
    b83ea22cf [wforget] Check if asyncRequestExecutor is initialized before 
shutdown
    
    Authored-by: wforget <[email protected]>
    Signed-off-by: Cheng Pan <[email protected]>
    (cherry picked from commit a95ff125fc7a6bc1ebc78cda551e1ae9e5e0dac9)
    Signed-off-by: Cheng Pan <[email protected]>
---
 .../scala/org/apache/kyuubi/client/KyuubiSyncThriftClient.scala  | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git 
a/kyuubi-server/src/main/scala/org/apache/kyuubi/client/KyuubiSyncThriftClient.scala
 
b/kyuubi-server/src/main/scala/org/apache/kyuubi/client/KyuubiSyncThriftClient.scala
index 160492fcb..5ba67cf35 100644
--- 
a/kyuubi-server/src/main/scala/org/apache/kyuubi/client/KyuubiSyncThriftClient.scala
+++ 
b/kyuubi-server/src/main/scala/org/apache/kyuubi/client/KyuubiSyncThriftClient.scala
@@ -67,9 +67,12 @@ class KyuubiSyncThriftClient private (
   private var engineAliveThreadPool: ScheduledExecutorService = _
   @volatile private var engineLastAlive: Long = _
 
-  private lazy val asyncRequestExecutor: ExecutorService =
+  @volatile private var asyncRequestExecutorInitialized: Boolean = false
+  private lazy val asyncRequestExecutor: ExecutorService = {
+    asyncRequestExecutorInitialized = true
     ThreadUtils.newDaemonSingleThreadScheduledExecutor(
       "async-request-executor-" + SessionHandle(_remoteSessionHandle))
+  }
 
   @VisibleForTesting
   @volatile private[kyuubi] var asyncRequestInterrupted: Boolean = false
@@ -78,7 +81,9 @@ class KyuubiSyncThriftClient private (
   private[kyuubi] def getEngineAliveProbeProtocol: Option[TProtocol] = 
engineAliveProbeProtocol
 
   private def shutdownAsyncRequestExecutor(): Unit = {
-    
Option(asyncRequestExecutor).filterNot(_.isShutdown).foreach(ThreadUtils.shutdown(_))
+    if (asyncRequestExecutorInitialized && !asyncRequestExecutor.isShutdown) {
+      ThreadUtils.shutdown(asyncRequestExecutor)
+    }
     asyncRequestInterrupted = true
   }
 

Reply via email to