HyukjinKwon commented on code in PR #50017: URL: https://github.com/apache/spark/pull/50017#discussion_r1963035005
########## sql/connect/common/src/main/scala/org/apache/spark/sql/connect/SparkSession.scala: ########## @@ -712,37 +729,41 @@ object SparkSession extends SparkSessionCompanion with Logging { } } - val maybeConnectScript = - Option(System.getenv("SPARK_HOME")).map(Paths.get(_, "sbin", "start-connect-server.sh")) - - if (server.isEmpty && - (remoteString.exists(_.startsWith("local")) || - (remoteString.isDefined && isAPIModeConnect)) && - maybeConnectScript.exists(Files.exists(_))) { - server = Some { - val args = - Seq(maybeConnectScript.get.toString, "--master", remoteString.get) ++ sparkOptions - .filter(p => !p._1.startsWith("spark.remote")) - .flatMap { case (k, v) => Seq("--conf", s"$k=$v") } - val pb = new ProcessBuilder(args: _*) - // So don't exclude spark-sql jar in classpath - pb.environment().remove(SparkConnectClient.SPARK_REMOTE) - pb.start() - } - - // Let the server start. We will directly request to set the configurations - // and this sleep makes less noisy with retries. - Thread.sleep(2000L) - System.setProperty("spark.remote", "sc://localhost") - - // scalastyle:off runtimeaddshutdownhook - Runtime.getRuntime.addShutdownHook(new Thread() { - override def run(): Unit = if (server.isDefined) { - new ProcessBuilder(maybeConnectScript.get.toString) - .start() + server.synchronized { + if (server.isEmpty && + (remoteString.exists(_.startsWith("local")) || + (remoteString.isDefined && isAPIModeConnect)) && + maybeConnectStartScript.exists(Files.exists(_))) { + server = Some { + val args = + Seq( + maybeConnectStartScript.get.toString, + "--master", + remoteString.get) ++ sparkOptions + .filter(p => !p._1.startsWith("spark.remote")) + .filter(p => !p._1.startsWith("spark.api.mode")) + .flatMap { case (k, v) => Seq("--conf", s"$k=$v") } + val pb = new ProcessBuilder(args: _*) + // So don't exclude spark-sql jar in classpath + pb.environment().remove(SparkConnectClient.SPARK_REMOTE) + pb.environment().put("SPARK_LOCAL_CONNECT", "1") + pb.start() } - }) - // scalastyle:on runtimeaddshutdownhook + + // Let the server start. We will directly request to set the configurations + // and this sleep makes less noisy with retries. + Thread.sleep(2000L) Review Comment: We do like wait until logfile is created or sth .. I will take a seperate look it is original code in any event. Here I just added synchronized -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org