You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by ab...@apache.org on 2023/09/03 01:20:11 UTC

[kafka] branch 3.6 updated (8eb9105e51c -> 3f1a459873c)

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

ableegoldman pushed a change to branch 3.6
in repository https://gitbox.apache.org/repos/asf/kafka.git


    from 8eb9105e51c KAFKA-15427: Fix resource leak in integration tests for tiered storage (#14319)
     new ac4bdb2111c KAFKA-15429: catch+log errors from unsubscribe in streamthread shutdown (#14325)
     new 3f1a459873c KAFKA-15429: reset transactionInFlight on StreamsProducer close (#14326)

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../streams/processor/internals/StreamThread.java  |  8 +++++--
 .../processor/internals/StreamsProducer.java       |  5 ++--
 .../processor/internals/StreamsProducerTest.java   | 28 ++++++++++++++++++++++
 3 files changed, 37 insertions(+), 4 deletions(-)


[kafka] 02/02: KAFKA-15429: reset transactionInFlight on StreamsProducer close (#14326)

Posted by ab...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ableegoldman pushed a commit to branch 3.6
in repository https://gitbox.apache.org/repos/asf/kafka.git

commit 3f1a459873ca3cd0efd75819d44d1642b61836a2
Author: Rohan <de...@gmail.com>
AuthorDate: Sat Sep 2 18:14:14 2023 -0700

    KAFKA-15429: reset transactionInFlight on StreamsProducer close (#14326)
    
    Resets the value of transactionInFlight to false when closing the
    StreamsProducer. This ensures we don't try to commit against a
    closed producer
    
    Reviewers: Anna Sophie Blee-Goldman <ab...@apache.org>
---
 .../processor/internals/StreamsProducer.java       |  5 ++--
 .../processor/internals/StreamsProducerTest.java   | 28 ++++++++++++++++++++++
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamsProducer.java b/streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamsProducer.java
index 61de201a4fa..bc8a3118fe7 100644
--- a/streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamsProducer.java
+++ b/streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamsProducer.java
@@ -192,12 +192,11 @@ public class StreamsProducer {
 
         oldProducerTotalBlockedTime += totalBlockedTime(producer);
         final long start = time.nanoseconds();
-        producer.close();
+        close();
         final long closeTime = time.nanoseconds() - start;
         oldProducerTotalBlockedTime += closeTime;
 
         producer = clientSupplier.getProducer(eosV2ProducerConfigs);
-        transactionInitialized = false;
     }
 
     private double getMetricValue(final Map<MetricName, ? extends Metric> metrics,
@@ -371,6 +370,8 @@ public class StreamsProducer {
 
     void close() {
         producer.close();
+        transactionInFlight = false;
+        transactionInitialized = false;
     }
 
     // for testing only
diff --git a/streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsProducerTest.java b/streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsProducerTest.java
index 9470a7b166e..1787e6092f0 100644
--- a/streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsProducerTest.java
+++ b/streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsProducerTest.java
@@ -207,6 +207,34 @@ public class StreamsProducerTest {
 
     // functional tests
 
+    @Test
+    public void shouldResetTransactionInFlightOnClose() {
+        // given:
+        eosBetaStreamsProducer.send(
+            new ProducerRecord<>("topic", new byte[1]), (metadata, error) -> { });
+        assertThat(eosBetaStreamsProducer.transactionInFlight(), is(true));
+
+        // when:
+        eosBetaStreamsProducer.close();
+
+        // then:
+        assertThat(eosBetaStreamsProducer.transactionInFlight(), is(false));
+    }
+
+    @Test
+    public void shouldResetTransactionInFlightOnReset() {
+        // given:
+        eosBetaStreamsProducer.send(
+            new ProducerRecord<>("topic", new byte[1]), (metadata, error) -> { });
+        assertThat(eosBetaStreamsProducer.transactionInFlight(), is(true));
+
+        // when:
+        eosBetaStreamsProducer.resetProducer();
+
+        // then:
+        assertThat(eosBetaStreamsProducer.transactionInFlight(), is(false));
+    }
+
     @Test
     public void shouldCreateProducer() {
         assertThat(mockClientSupplier.producers.size(), is(1));


[kafka] 01/02: KAFKA-15429: catch+log errors from unsubscribe in streamthread shutdown (#14325)

Posted by ab...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ableegoldman pushed a commit to branch 3.6
in repository https://gitbox.apache.org/repos/asf/kafka.git

commit ac4bdb2111c424fd8c409f4d2004d9083115a355
Author: Rohan <de...@gmail.com>
AuthorDate: Sat Sep 2 18:13:16 2023 -0700

    KAFKA-15429: catch+log errors from unsubscribe in streamthread shutdown (#14325)
    
    Preliminary fix for KAFKA-15429 which updates StreamThread.completeShutdown to
    catch-and-log errors from consumer.unsubscribe. Though this does not prevent
    the exception, it does preserve the original exception that caused the stream
    thread to exit.
    
    Reviewers: Anna Sophie Blee-Goldman <ab...@apache.org>
---
 .../apache/kafka/streams/processor/internals/StreamThread.java    | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamThread.java b/streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamThread.java
index 883ec25ff10..8d5fe3d5a0a 100644
--- a/streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamThread.java
+++ b/streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamThread.java
@@ -1196,8 +1196,12 @@ public class StreamThread extends Thread {
         } catch (final Throwable e) {
             log.error("Failed to close changelog reader due to the following error:", e);
         }
-        if (leaveGroupRequested.get()) {
-            mainConsumer.unsubscribe();
+        try {
+            if (leaveGroupRequested.get()) {
+                mainConsumer.unsubscribe();
+            }
+        } catch (final Throwable e) {
+            log.error("Failed to unsubscribe due to the following error: ", e);
         }
         try {
             mainConsumer.close();