LuciferYang commented on code in PR #41097:
URL: https://github.com/apache/spark/pull/41097#discussion_r1926611179
##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/SparkSession.scala:
##########
@@ -569,14 +569,38 @@ class SparkSession private[sql] (
override def close(): Unit = {
client.shutdown()
allocator.close()
+ SparkSession.onSessionClose(this)
}
}
// The minimal builder needed to create a spark session.
// TODO: implements all methods mentioned in the scaladoc of [[SparkSession]]
object SparkSession extends Logging {
+ private val MAX_CACHED_SESSIONS = 100
private val planIdGenerator = new AtomicLong
+ private val sessions = CacheBuilder
+ .newBuilder()
+ .weakValues()
+ .maximumSize(MAX_CACHED_SESSIONS)
Review Comment:
After running the test with `build/sbt clean "connect-client-jvm/test"
-Phive`, I see the following content in the `unit-tests.log`:
```
25/01/23 16:40:49.903 pool-1-thread-1-ScalaTest-running-ClientE2ETestSuite
ERROR ManagedChannelOrphanWrapper: *~*~*~ Previous channel
ManagedChannelImpl{logId=15, target=localhost:15642} was garbage collected
without being shut down! ~*~*~*
Make sure to call shutdown()/shutdownNow()
java.lang.RuntimeException: ManagedChannel allocation site
at
io.grpc.internal.ManagedChannelOrphanWrapper$ManagedChannelReference.<init>(ManagedChannelOrphanWrapper.java:102)
at
io.grpc.internal.ManagedChannelOrphanWrapper.<init>(ManagedChannelOrphanWrapper.java:60)
at
io.grpc.internal.ManagedChannelOrphanWrapper.<init>(ManagedChannelOrphanWrapper.java:51)
at
io.grpc.internal.ManagedChannelImplBuilder.build(ManagedChannelImplBuilder.java:709)
at
io.grpc.ForwardingChannelBuilder2.build(ForwardingChannelBuilder2.java:272)
at
org.apache.spark.sql.connect.client.SparkConnectClient$Configuration.createChannel(SparkConnectClient.scala:766)
at
org.apache.spark.sql.connect.client.SparkConnectClient$Configuration.toSparkConnectClient(SparkConnectClient.scala:769)
at
org.apache.spark.sql.connect.client.SparkConnectClient$Builder.build(SparkConnectClient.scala:685)
at
org.apache.spark.sql.ClientE2ETestSuite.$anonfun$new$57(ClientE2ETestSuite.scala:423)
at org.scalatest.OutcomeOf.outcomeOf(OutcomeOf.scala:85)
at org.scalatest.OutcomeOf.outcomeOf$(OutcomeOf.scala:83)
at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
at org.scalatest.Transformer.apply(Transformer.scala:22)
at org.scalatest.Transformer.apply(Transformer.scala:20)
at
org.scalatest.funsuite.AnyFunSuiteLike$$anon$1.apply(AnyFunSuiteLike.scala:226)
at org.scalatest.TestSuite.withFixture(TestSuite.scala:196)
at org.scalatest.TestSuite.withFixture$(TestSuite.scala:195)
at
org.scalatest.funsuite.AnyFunSuite.withFixture(AnyFunSuite.scala:1564)
at
org.scalatest.funsuite.AnyFunSuiteLike.invokeWithFixture$1(AnyFunSuiteLike.scala:224)
at
org.scalatest.funsuite.AnyFunSuiteLike.$anonfun$runTest$1(AnyFunSuiteLike.scala:236)
at org.scalatest.SuperEngine.runTestImpl(Engine.scala:306)
at
org.scalatest.funsuite.AnyFunSuiteLike.runTest(AnyFunSuiteLike.scala:236)
at
org.scalatest.funsuite.AnyFunSuiteLike.runTest$(AnyFunSuiteLike.scala:218)
at org.scalatest.funsuite.AnyFunSuite.runTest(AnyFunSuite.scala:1564)
at
org.scalatest.funsuite.AnyFunSuiteLike.$anonfun$runTests$1(AnyFunSuiteLike.scala:269)
at
org.scalatest.SuperEngine.$anonfun$runTestsInBranch$1(Engine.scala:413)
at scala.collection.immutable.List.foreach(List.scala:334)
at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:401)
at org.scalatest.SuperEngine.runTestsInBranch(Engine.scala:396)
at org.scalatest.SuperEngine.runTestsImpl(Engine.scala:475)
at
org.scalatest.funsuite.AnyFunSuiteLike.runTests(AnyFunSuiteLike.scala:269)
at
org.scalatest.funsuite.AnyFunSuiteLike.runTests$(AnyFunSuiteLike.scala:268)
at
org.scalatest.funsuite.AnyFunSuite.runTests(AnyFunSuite.scala:1564)
```
https://github.com/grpc/grpc-java/blob/24085103b926559659ecd3941a3308479876f084/core/src/main/java/io/grpc/internal/ManagedChannelOrphanWrapper.java#L149-L172

From the code that prints the logs, it seems that only the references of
unshutdown sessions are being printed. Is there a risk of resource leak here?
I created SPARK-50961 to record this, and I don't have a definitive answer
to it yet. If there's no risk, feel free to close it.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]