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

dongjoon-hyun pushed a commit to branch branch-4.1
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/branch-4.1 by this push:
     new eadba0e0592c [SPARK-61357][SS][TEST] Close Kafka producers in 
`KafkaRealTimeModeE2ESuite` and `KafkaRealTimeIntegrationSuite`
eadba0e0592c is described below

commit eadba0e0592c55e30284be8122698c93ea01d06f
Author: Dongjoon Hyun <[email protected]>
AuthorDate: Tue Nov 10 08:31:28 2026 -0800

    [SPARK-61357][SS][TEST] Close Kafka producers in 
`KafkaRealTimeModeE2ESuite` and `KafkaRealTimeIntegrationSuite`
    
    ### What changes were proposed in this pull request?
    
    This PR aims to close the Kafka producers in `KafkaRealTimeModeE2ESuite` 
and `KafkaRealTimeIntegrationSuite`.
    
    ### Why are the changes needed?
    
    The following test cases create `KafkaProducer`s, but never close them.
    - `KafkaRealTimeModeE2ESuite`: `Union two kafka streams, for each write to 
sink` (`producer1` and `producer2`)
    - `KafkaRealTimeIntegrationSuite`: `e2e stateless` (`producer`)
    
    After a suite stops its embedded Kafka broker, the leaked producers keep 
reconnecting to the old broker port. If a later suite in the same JVM binds a 
server to the same port, a leaked producer connects to it and sends a Kafka 
`ApiVersions` request.
    
    This happened in the following `branch-4.3` CI run and failed 
`KafkaRealTimeModeAggregationSuite`.
    - https://github.com/apache/spark/actions/runs/42751612477/job/129620645754
    
    1. `tumbling window avg` of `KafkaRealTimeModeAggregationSuite` started a 
Real-Time Mode streaming shuffle server at `127.0.0.1:41521`, which 
`KafkaRealTimeModeE2ESuite` had used for its broker before.
    2. `producer-442`, which `Union two kafka streams, for each write to sink` 
created, connected to that server. The server decoded the Kafka request header 
as a frame length and failed the query. `206159609852` plus the 8-byte length 
field is `0x0000003000120004`, i.e., a request of size 48 with `api_key` 18 
(`ApiVersions`) and `api_version` 4.
    
    ```
    26/11/10 04:49:55.143 streaming-shuffle-writer-13-3-server-825-3 WARN 
TransportChannelHandler: Exception in connection from /127.0.0.1:34032
    java.lang.IllegalArgumentException: Too large frame: 206159609852
        at 
org.apache.spark.network.util.JavaUtils.checkArgument(JavaUtils.java:759)
        at 
org.apache.spark.network.util.TransportFrameDecoder.decodeNext(TransportFrameDecoder.java:147)
    ...
    26/11/10 04:49:55.144 streaming-shuffle-writer-13-3-server-825-3 ERROR 
ErrorNotifier: A fatal error has occurred.
    26/11/10 04:49:55.144 kafka-producer-network-thread | producer-442 INFO 
NetworkClient: [Producer clientId=producer-442] Cancelled in-flight 
API_VERSIONS request with correlation id 307 due to node 0 being disconnected 
...
    ```
    
    3. Since the query was terminated at batch 1, the test timed out.
    
    ```
    The code passed to eventually never returned normally. Attempted 3968 times 
over 1.0002503943666665 minutes. Last failure message: 1 was not equal to 2.
    ```
    
    These producers have been leaked since SPARK-54027 added the test cases in 
Apache Spark 4.1.0 
([v4.1.0](https://github.com/apache/spark/releases/tag/v4.1.0), 2025-12-11).
    
    ### Does this PR introduce _any_ user-facing change?
    
    No, this is a test-only change.
    
    ### How was this patch tested?
    
    Pass the CIs.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Generated-by: Claude Opus 5.5
    
    Closes #60292 from dongjoon-hyun/SPARK-61357.
    
    Authored-by: Dongjoon Hyun <[email protected]>
    Signed-off-by: Dongjoon Hyun <[email protected]>
    
    (cherry picked from commit 0ec1f94dece269219f2b2d920fd5086a50c728f8)
    Signed-off-by: Dongjoon Hyun <[email protected]>
---
 .../sql/kafka010/KafkaRealTimeIntegrationSuite.scala   | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git 
a/connector/kafka-0-10-sql/src/test/scala/org/apache/spark/sql/kafka010/KafkaRealTimeIntegrationSuite.scala
 
b/connector/kafka-0-10-sql/src/test/scala/org/apache/spark/sql/kafka010/KafkaRealTimeIntegrationSuite.scala
index a359dc355478..b809bbfb9ed3 100644
--- 
a/connector/kafka-0-10-sql/src/test/scala/org/apache/spark/sql/kafka010/KafkaRealTimeIntegrationSuite.scala
+++ 
b/connector/kafka-0-10-sql/src/test/scala/org/apache/spark/sql/kafka010/KafkaRealTimeIntegrationSuite.scala
@@ -65,6 +65,8 @@ class KafkaRealTimeModeE2ESuite extends KafkaSourceTest with 
StreamRealTimeModeE
 
   test("Union two kafka streams, for each write to sink") {
     var q: StreamingQuery = null
+    var producer1: Producer[String, String] = null
+    var producer2: Producer[String, String] = null
     try {
       val topic1 = newTopic()
       val topic2 = newTopic()
@@ -72,8 +74,8 @@ class KafkaRealTimeModeE2ESuite extends KafkaSourceTest with 
StreamRealTimeModeE
       testUtils.createTopic(topic2, partitions = 2)
 
       val props: Properties = getKafkaConsumerProperties
-      val producer1: Producer[String, String] = new KafkaProducer[String, 
String](props)
-      val producer2: Producer[String, String] = new KafkaProducer[String, 
String](props)
+      producer1 = new KafkaProducer[String, String](props)
+      producer2 = new KafkaProducer[String, String](props)
 
       val readStream1 = spark.readStream
         .format("kafka")
@@ -143,6 +145,12 @@ class KafkaRealTimeModeE2ESuite extends KafkaSourceTest 
with StreamRealTimeModeE
       if (q != null) {
         q.stop()
       }
+      if (producer1 != null) {
+        producer1.close()
+      }
+      if (producer2 != null) {
+        producer2.close()
+      }
     }
   }
 }
@@ -188,6 +196,7 @@ class KafkaRealTimeIntegrationSuite
 
   test("e2e stateless") {
     var query: StreamingQuery = null
+    var producer: Producer[String, String] = null
     try {
       val inputTopic = newTopic()
       testUtils.createTopic(inputTopic, partitions = 5)
@@ -202,7 +211,7 @@ class KafkaRealTimeIntegrationSuite
       props.put("value.serializer", 
"org.apache.kafka.common.serialization.StringSerializer");
       props.put("compression.type", "snappy")
 
-      val producer: Producer[String, String] = new KafkaProducer[String, 
String](props)
+      producer = new KafkaProducer[String, String](props)
 
       query = spark.readStream
         .format("kafka")
@@ -288,6 +297,9 @@ class KafkaRealTimeIntegrationSuite
       if (query != null) {
         query.stop()
       }
+      if (producer != null) {
+        producer.close()
+      }
     }
   }
 }


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

Reply via email to