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

wenchen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new d5794207ee89 [SPARK-55693][SQL] Avoid deadlock by making 
SparkSession.observationManager a non-lazy val
d5794207ee89 is described below

commit d5794207ee89c3b95f805196607a52643a755b79
Author: Yihong He <[email protected]>
AuthorDate: Wed Mar 4 20:52:20 2026 +0800

    [SPARK-55693][SQL] Avoid deadlock by making SparkSession.observationManager 
a non-lazy val
    
    ### What changes were proposed in this pull request?
    
    Change `SparkSession.observationManager` from a `lazy val` to a regular 
`val` in `SparkSession.scala`.
    
    ### Why are the changes needed?
    
    Using `lazy val` for `observationManager` can cause deadlocks because 
initializing it locks the SparkSession instance. Making it a non-lazy `val` 
initializes it at construction time and removes this deadlock risk.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No
    
    ### How was this patch tested?
    
    Existing tests
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Yes
    
    Closes #54491 from heyihong/SPARK-55693.
    
    Authored-by: Yihong He <[email protected]>
    Signed-off-by: Wenchen Fan <[email protected]>
---
 .../src/main/scala/org/apache/spark/sql/classic/SparkSession.scala    | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git 
a/sql/core/src/main/scala/org/apache/spark/sql/classic/SparkSession.scala 
b/sql/core/src/main/scala/org/apache/spark/sql/classic/SparkSession.scala
index fef62d8b2755..f03b4796314b 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/classic/SparkSession.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/classic/SparkSession.scala
@@ -909,8 +909,10 @@ class SparkSession private(
       override protected def conf: SQLConf = sessionState.conf
     }
 
+  // Avoid using lazy val here because it locks the SparkSession instance
+  // when initializing observationManager and may cause deadlocks.
   @transient
-  private[sql] lazy val observationManager = new ObservationManager(this)
+  private[sql] val observationManager = new ObservationManager(this)
 
   override private[sql] def isUsable: Boolean = !sparkContext.isStopped
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to