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

cloud-fan 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 433aee3f46b0 [SPARK-58094][CONNECT][FOLLOWUP] Fix flaky BindException 
in SparkConnectServiceKeepAliveSuite
433aee3f46b0 is described below

commit 433aee3f46b0e598835e338477b820991981b9ad
Author: Vinod KC <[email protected]>
AuthorDate: Sat Jul 18 05:55:20 2026 +0800

    [SPARK-58094][CONNECT][FOLLOWUP] Fix flaky BindException in 
SparkConnectServiceKeepAliveSuite
    
    ### What changes were proposed in this pull request?
    
    Three tests in `SparkConnectServiceKeepAliveSuite` each call 
`SparkConnectService.stop()` immediately followed by 
`SparkConnectService.start()` on the same port. The bare `stop()` uses 
`server.shutdownNow()` which is non-blocking — the OS-level TCP socket may 
still be bound when `start()` tries to bind, causing an intermittent 
`BindException` with `maxRetries=0`.
    
    The fix: replace the bare `stop()` calls in these tests with 
`stop(Some(30), Some(TimeUnit.SECONDS))`. This takes the existing `if`-branch 
in `stop()` that calls `server.shutdown()` followed by 
`server.awaitTermination(30s)`, giving the server time to fully release the 
port before returning. The production `stop()` code is unchanged.
    
    ### Why are the changes needed?
    
    `SparkConnectServiceKeepAliveSuite` (introduced in #57202) was hitting 
intermittent CI failures:
    
    java.net.BindException: Failed to bind to address 0.0.0.0/0.0.0.0:15312:
    Service 'org.apache.spark.sql.connect.service.SparkConnectService' failed
    after 0 retries (starting from 15312)!
    
    ### Does this PR introduce _any_ user-facing change?
    
    No. The change is test-only. Production code is unchanged.
    
    ### How was this patch tested?
    
    The existing `SparkConnectServiceKeepAliveSuite` tests cover the stop/start 
lifecycle. No new tests are needed — this fix eliminates the race those tests 
were hitting. Scala and Python linters pass.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Generated-by: Claude Sonnet 4.6
    
    Closes #57342 from vinodkc/fix-spark58094-flaky-test.
    
    Authored-by: Vinod KC <[email protected]>
    Signed-off-by: Wenchen Fan <[email protected]>
---
 .../connect/service/SparkConnectServiceKeepAliveSuite.scala  | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git 
a/sql/connect/server/src/test/scala/org/apache/spark/sql/connect/service/SparkConnectServiceKeepAliveSuite.scala
 
b/sql/connect/server/src/test/scala/org/apache/spark/sql/connect/service/SparkConnectServiceKeepAliveSuite.scala
index d1d273016e76..de8d6b84e30d 100644
--- 
a/sql/connect/server/src/test/scala/org/apache/spark/sql/connect/service/SparkConnectServiceKeepAliveSuite.scala
+++ 
b/sql/connect/server/src/test/scala/org/apache/spark/sql/connect/service/SparkConnectServiceKeepAliveSuite.scala
@@ -121,7 +121,7 @@ class SparkConnectServiceKeepAliveSuite extends 
SparkConnectServerTest {
     // behavior), this client's cadence would violate that coupled invariant; 
with today's fixed,
     // decoupled GRPC_KEEPALIVE_PERMIT_TIME_SECONDS floor (10s), it's 
comfortably tolerated.
     val clientKeepAliveMs = 
(SparkConnectService.GRPC_KEEPALIVE_PERMIT_TIME_SECONDS + 1) * 1000
-    SparkConnectService.stop()
+    SparkConnectService.stop(Some(30), Some(TimeUnit.SECONDS))
     withSparkEnvConfs(
       Connect.CONNECT_GRPC_BINDING_PORT.key -> serverPort.toString,
       Connect.CONNECT_GRPC_KEEPALIVE_ENABLED.key -> "true",
@@ -156,7 +156,7 @@ class SparkConnectServiceKeepAliveSuite extends 
SparkConnectServerTest {
         client.shutdown()
       }
     } finally {
-      SparkConnectService.stop()
+      SparkConnectService.stop(Some(30), Some(TimeUnit.SECONDS))
       withSparkEnvConfs(
         Connect.CONNECT_GRPC_BINDING_PORT.key -> serverPort.toString,
         Connect.CONNECT_GRPC_KEEPALIVE_ENABLED.key -> "true",
@@ -190,7 +190,7 @@ class SparkConnectServiceKeepAliveSuite extends 
SparkConnectServerTest {
     // truly idle connection -- hence one call to establish the transport, 
then real idle time
     // (no further calls) spanning several ping intervals, then a 
connection-count check.
     val clientKeepAliveMs = 
(SparkConnectService.GRPC_KEEPALIVE_PERMIT_TIME_SECONDS + 1) * 1000
-    SparkConnectService.stop()
+    SparkConnectService.stop(Some(30), Some(TimeUnit.SECONDS))
     withSparkEnvConfs(
       Connect.CONNECT_GRPC_BINDING_PORT.key -> serverPort.toString,
       Connect.CONNECT_GRPC_KEEPALIVE_ENABLED.key -> "false",
@@ -238,7 +238,7 @@ class SparkConnectServiceKeepAliveSuite extends 
SparkConnectServerTest {
       }
     } finally {
       relay.close()
-      SparkConnectService.stop()
+      SparkConnectService.stop(Some(30), Some(TimeUnit.SECONDS))
       withSparkEnvConfs(
         Connect.CONNECT_GRPC_BINDING_PORT.key -> serverPort.toString,
         Connect.CONNECT_GRPC_KEEPALIVE_ENABLED.key -> "true",
@@ -253,7 +253,7 @@ class SparkConnectServiceKeepAliveSuite extends 
SparkConnectServerTest {
     "SPARK-58094: disabling spark.connect.grpc.keepAlive.enabled reverts to 
the pre-fix hang") {
     // Restart the real service with keepalive fully disabled (not just given 
short/aggressive
     // timing) to prove the flag genuinely gates the fix rather than only 
tuning its timing.
-    SparkConnectService.stop()
+    SparkConnectService.stop(Some(30), Some(TimeUnit.SECONDS))
     withSparkEnvConfs(
       Connect.CONNECT_GRPC_BINDING_PORT.key -> serverPort.toString,
       Connect.CONNECT_GRPC_KEEPALIVE_ENABLED.key -> "false",
@@ -321,7 +321,7 @@ class SparkConnectServiceKeepAliveSuite extends 
SparkConnectServerTest {
       }
     } finally {
       // Restore the enabled server for afterAll()/subsequent tests in this 
suite.
-      SparkConnectService.stop()
+      SparkConnectService.stop(Some(30), Some(TimeUnit.SECONDS))
       withSparkEnvConfs(
         Connect.CONNECT_GRPC_BINDING_PORT.key -> serverPort.toString,
         Connect.CONNECT_GRPC_KEEPALIVE_ENABLED.key -> "true",


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

Reply via email to