Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-32165

SessionState leaks SparkListener with multiple SparkSession

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Not A Problem
    • 3.0.0
    • None
    • SQL
    • None

    Description

      Copied from https://github.com/apache/spark/pull/28128#issuecomment-653102770

      I'd like to point out that this pr (https://github.com/apache/spark/pull/28128) doesn't fix the memory leaky completely. Once SessionState is touched, it will add two more listeners into the SparkContext, namely SQLAppStatusListener and ExecutionListenerBus

      It can be reproduced easily as

        test("SPARK-31354: SparkContext only register one SparkSession ApplicationEnd listener") {
          val conf = new SparkConf()
            .setMaster("local")
            .setAppName("test-app-SPARK-31354-1")
          val context = new SparkContext(conf)
          SparkSession
            .builder()
            .sparkContext(context)
            .master("local")
            .getOrCreate()
            .sessionState // this touches the sessionState
          val postFirstCreation = context.listenerBus.listeners.size()
          SparkSession.clearActiveSession()
          SparkSession.clearDefaultSession()
      
          SparkSession
            .builder()
            .sparkContext(context)
            .master("local")
            .getOrCreate()
            .sessionState // this touches the sessionState
          val postSecondCreation = context.listenerBus.listeners.size()
          SparkSession.clearActiveSession()
          SparkSession.clearDefaultSession()
          assert(postFirstCreation == postSecondCreation)
        }
      

      The problem can be reproduced by the above code.

      Attachments

        Activity

          People

            Unassigned Unassigned
            advancedxy YE
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: