You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "philipnee (via GitHub)" <gi...@apache.org> on 2023/03/29 20:04:56 UTC

[GitHub] [kafka] philipnee opened a new pull request, #13477: KAFKA-7499: Handle serialization error in ProductionExceptionHandler

philipnee opened a new pull request, #13477:
URL: https://github.com/apache/kafka/pull/13477

   We want to allow ProductionExceptionHandler to handle serialization errors. In the PR, I modified the `handleSerializationError` in `DefaultProductionExceptionHandler` and the `AlwaysContinueProductionExceptionHandler` to handle the failure.
   
   ### Committer Checklist (excluded from commit message)
   - [ ] Verify design and implementation 
   - [ ] Verify test coverage and CI build status
   - [ ] Verify documentation (including upgrade notes)
   


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] mjsax commented on a diff in pull request #13477: KAFKA-7499: Handle serialization error in ProductionExceptionHandler

Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #13477:
URL: https://github.com/apache/kafka/pull/13477#discussion_r1163702670


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/RecordCollectorImpl.java:
##########
@@ -213,6 +212,31 @@ public <K, V> void send(final String topic,
                     keyClass,
                     valueClass),
                 exception);
+        } catch (final SerializationException exception) {

Review Comment:
   As pointed out during the KIP discussion, the new handler should also cover `ClassCastException` -- we only had a special catch-block for it, to get a better error message (we still want a good error message for this case, but we should also apply the handler and allow people to CONTINUE on a ClassCastException).



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] philipnee commented on a diff in pull request #13477: KAFKA-7499: Handle serialization error in ProductionExceptionHandler

Posted by "philipnee (via GitHub)" <gi...@apache.org>.
philipnee commented on code in PR #13477:
URL: https://github.com/apache/kafka/pull/13477#discussion_r1153927450


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/RecordCollectorImpl.java:
##########
@@ -213,6 +212,31 @@ public <K, V> void send(final String topic,
                     keyClass,
                     valueClass),
                 exception);
+        } catch (final SerializationException exception) {
+            final ProducerRecord<K, V> record = new ProducerRecord<>(topic, partition, timestamp, key, value, headers);
+            final ProductionExceptionHandler.ProductionExceptionHandlerResponse response;
+            try {
+                response = productionExceptionHandler.handleSerializationException(record, exception);
+            } catch (final Exception fatalUserException) {
+                log.error("Serialization error callback failed after serialization error for record {}", record, fatalUserException);
+                final ProducerRecord<byte[], byte[]> rec = new ProducerRecord<>(topic, partition, timestamp, keyBytes, valBytes, headers);

Review Comment:
   valBytes is always null - maybe it is more straightforward to supply a null here?



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] philipnee commented on a diff in pull request #13477: KAFKA-7499: Handle serialization error in ProductionExceptionHandler

Posted by "philipnee (via GitHub)" <gi...@apache.org>.
philipnee commented on code in PR #13477:
URL: https://github.com/apache/kafka/pull/13477#discussion_r1166276780


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/RecordCollectorImpl.java:
##########
@@ -213,6 +212,32 @@ public <K, V> void send(final String topic,
                     keyClass,
                     valueClass),
                 exception);
+        } catch (final SerializationException exception) {
+            final ProducerRecord<K, V> record = new ProducerRecord<>(topic, partition, timestamp, key, value, headers);
+            final ProductionExceptionHandler.ProductionExceptionHandlerResponse response;
+
+            log.debug("Error serializing record to topic {} due to {}", topic, exception);
+
+            try {
+                response = productionExceptionHandler.handleSerializationException(record, exception);
+            } catch (final Exception e) {
+                log.error("Fatal when handling serialization exception", e);
+                recordSendError(topic, e, null);
+                return;
+            }
+
+            if (response == ProductionExceptionHandlerResponse.FAIL) {
+                log.error("Fatal due to SerializationException.", exception);
+                droppedRecordsSensor.record();
+                throw exception;
+            }
+
+            log.warn("Unable to serialize record, continue processing. " +
+                    "ProducerRecord(topic=[{}], partition=[{}], timestamp=[{}])",
+                topic,
+                partition,
+                timestamp);
+

Review Comment:
   oh god, thanks for catching this.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] philipnee commented on a diff in pull request #13477: KAFKA-7499: Handle serialization error in ProductionExceptionHandler

Posted by "philipnee (via GitHub)" <gi...@apache.org>.
philipnee commented on code in PR #13477:
URL: https://github.com/apache/kafka/pull/13477#discussion_r1167093584


##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/RecordCollectorTest.java:
##########
@@ -1391,21 +1390,57 @@ public void shouldNotCloseInternalProducerForNonEOS() {
     }
 
     @Test
-    public void testCollectorFlush_ThrowsStreamsExceptionUsingDefaultExceptionHandler() {
-        final ErrorStringSerializer errorSerializer = new ErrorStringSerializer();
-        final RecordCollector collector = newRecordCollector(new DefaultProductionExceptionHandler());
-        collector.initialize();
-        collector.send(topic, "key", "val", null, 0, null, stringSerializer, errorSerializer, sinkNodeName, context);
-        assertThrows(StreamsException.class, collector::flush);
+    public void shouldThrowStreamsExceptionUsingDefaultExceptionHandler() {
+        try (final ErrorStringSerializer errorSerializer = new ErrorStringSerializer()) {
+            final RecordCollector collector = newRecordCollector(new DefaultProductionExceptionHandler());
+            collector.initialize();
+
+            final StreamsException error = assertThrows(
+                StreamsException.class,
+                () -> collector.send(topic, "key", "val", null, 0, null, stringSerializer, errorSerializer, sinkNodeName, context)
+            );
+
+            assertThat(error.getCause(), instanceOf(SerializationException.class));
+        }
     }
 
     @Test
-    public void testCollectorFlush_DoesNotThrowStreamsExceptionUsingAlwaysContinueExceptionHandler() {
-        final ErrorStringSerializer errorSerializer = new ErrorStringSerializer();
-        final RecordCollector collector = newRecordCollector(new AlwaysContinueProductionExceptionHandler());
-        collector.initialize();
-        collector.send(topic, "key", "val", null, 0, null, errorSerializer, stringSerializer, sinkNodeName, context);
-        assertDoesNotThrow(collector::flush);
+    public void shouldDropRecordExceptionUsingAlwaysContinueExceptionHandler() {
+        try (final ErrorStringSerializer errorSerializer = new ErrorStringSerializer()) {
+            final RecordCollector collector = newRecordCollector(new AlwaysContinueProductionExceptionHandler());
+            collector.initialize();
+
+            collector.send(topic, "key", "val", null, 0, null, errorSerializer, stringSerializer, sinkNodeName, context);
+
+            assertThat(mockProducer.history().isEmpty(), equalTo(true));
+            assertThat(
+                streamsMetrics.metrics().get(new MetricName(
+                    "dropped-records-total",
+                    "stream-task-metrics",
+                    "The total number of dropped records",
+                    mkMap(
+                        mkEntry("thread-id", Thread.currentThread().getName()),
+                        mkEntry("task-id", taskId.toString())
+                    ))).metricValue(),
+                equalTo(1.0)
+            );
+        }
+    }
+
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    @Test
+    public void shouldNotCallProductionExceptionHandlerOnClassCastException() {
+        try (final ErrorStringSerializer errorSerializer = new ErrorStringSerializer()) {
+            final RecordCollector collector = newRecordCollector(new AlwaysContinueProductionExceptionHandler());
+            collector.initialize();
+

Review Comment:
   Here's a minor PR: https://github.com/apache/kafka/pull/13576
   
   



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] mjsax commented on a diff in pull request #13477: KAFKA-7499: Handle serialization error in ProductionExceptionHandler

Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #13477:
URL: https://github.com/apache/kafka/pull/13477#discussion_r1167090307


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/RecordCollectorImpl.java:
##########
@@ -212,11 +212,11 @@ public <K, V> void send(final String topic,
                     keyClass,
                     valueClass),
                 exception);
-        } catch (final SerializationException exception) {
+        } catch (final Exception exception) {

Review Comment:
   > I guess the intention is to catch all other errors during serialization
   
   Yes. The only excluded case is `ClassCastException`.
   
   >  I think this is fine, I don't know if there are exceptions but I guess not
   
   We don't really know what exception might be throw -- I guess we could relax this to `RuntimeException` but it also does not hurt to use `Exception`.
   
   > seems like the handler should either indicating there's an error and rethrow or continue.
   
   Not sure what you mean by this? Can you elaborate? If the handler itself fail, we throw. If the handler returns `FAIL` we also re-throw the exception (just wrapped as `StreamsException`). If the handler return `CONTINUE` we log a WARN and continue (via `return`).



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] mjsax commented on pull request #13477: KAFKA-7499: Handle serialization error in ProductionExceptionHandler

Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on PR #13477:
URL: https://github.com/apache/kafka/pull/13477#issuecomment-1506098834

   > I believe I saw something about the class casting handling but I couldn't see that in the comments.
   
   I did leave a commend on the PR, but delete it later as the comment was wrong -- the KIP expliclity says that `ClassCastException` should be excluded and we should always fail, and not allow to skip over it via the handler.


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] mjsax commented on a diff in pull request #13477: KAFKA-7499: Handle serialization error in ProductionExceptionHandler

Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #13477:
URL: https://github.com/apache/kafka/pull/13477#discussion_r1164381176


##########
streams/src/main/java/org/apache/kafka/streams/errors/ProductionExceptionHandler.java:
##########
@@ -34,6 +35,18 @@ public interface ProductionExceptionHandler extends Configurable {
     ProductionExceptionHandlerResponse handle(final ProducerRecord<byte[], byte[]> record,
                                               final Exception exception);
 
+    /**
+     * Handles serialization exception and determine if the process should continue. The default implementation is to
+     * fail the process.
+     *
+     * @param record        the record that failed to serialize
+     * @param exception     the exception that occurred during serialization
+     */
+    default ProductionExceptionHandlerResponse onSerializationException(final ProducerRecord record,

Review Comment:
   I think it's correct to have `Exception` as it's more generic. Guess we could actually make it a `RuntimeException` but limiting it to `SerializationException` might be too restrictive, because the interface of `org.apache.kafka.common.serialization.Serializer#serialize` does not declare what exception might be throw, so it could be anything?



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] philipnee commented on a diff in pull request #13477: KAFKA-7499: Handle serialization error in ProductionExceptionHandler

Posted by "philipnee (via GitHub)" <gi...@apache.org>.
philipnee commented on code in PR #13477:
URL: https://github.com/apache/kafka/pull/13477#discussion_r1153962114


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/RecordCollectorImpl.java:
##########
@@ -213,6 +212,30 @@ public <K, V> void send(final String topic,
                     keyClass,
                     valueClass),
                 exception);
+        } catch (final SerializationException exception) {
+            final ProducerRecord<K, V> record = new ProducerRecord<>(topic, partition, timestamp, key, value, headers);
+            final ProductionExceptionHandler.ProductionExceptionHandlerResponse response;
+            try {
+                response = productionExceptionHandler.handleSerializationException(record, exception);
+            } catch (final Exception e) {
+                log.error("Fatal handling serialization exception on record {}", record, e);
+                recordSendError(topic, e, null);
+                return;
+            }
+
+            if (response == ProductionExceptionHandlerResponse.FAIL) {
+                recordSendError(topic, exception, null);
+                return;
+            }
+
+            log.info("Unable to serialize {}. Continue processing. " +

Review Comment:
   Do we actually want INFO level logging here? I wonder if it is going to wash out the log if we've got a huge batch of records that can't be serialized.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] mjsax merged pull request #13477: KAFKA-7499: Handle serialization error in ProductionExceptionHandler

Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax merged PR #13477:
URL: https://github.com/apache/kafka/pull/13477


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] philipnee commented on a diff in pull request #13477: KAFKA-7499: Handle serialization error in ProductionExceptionHandler

Posted by "philipnee (via GitHub)" <gi...@apache.org>.
philipnee commented on code in PR #13477:
URL: https://github.com/apache/kafka/pull/13477#discussion_r1164651827


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/RecordCollectorImpl.java:
##########
@@ -213,6 +212,31 @@ public <K, V> void send(final String topic,
                     keyClass,
                     valueClass),
                 exception);
+        } catch (final SerializationException exception) {
+            final ProducerRecord<K, V> record = new ProducerRecord<>(topic, partition, timestamp, key, value, headers);
+            final ProductionExceptionHandler.ProductionExceptionHandlerResponse response;
+            try {
+                response = productionExceptionHandler.onSerializationException(record, exception);
+            } catch (final Exception e) {
+                log.error("Fatal handling serialization exception on record {}", record, e);
+                recordSendError(topic, e, null);
+                return;
+            }
+
+            if (response == ProductionExceptionHandlerResponse.FAIL) {
+                log.error("Fatal handling serialization exception on record {}", record, exception);
+                recordSendError(topic, exception, null);
+                return;
+            }
+
+            log.warn("Unable to serialize {}. Continue processing. " +
+                    "ProducerRecord(key=[{}], value=[{}], topic=[{}], partition=[{}], timestamp=[{}])",
+                keyBytes == null ? "key" : "value",

Review Comment:
   hmm good point, maybe just log the continue processing message then.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] philipnee commented on a diff in pull request #13477: KAFKA-7499: Handle serialization error in ProductionExceptionHandler

Posted by "philipnee (via GitHub)" <gi...@apache.org>.
philipnee commented on code in PR #13477:
URL: https://github.com/apache/kafka/pull/13477#discussion_r1163702789


##########
streams/src/main/java/org/apache/kafka/streams/errors/ProductionExceptionHandler.java:
##########
@@ -34,6 +35,18 @@ public interface ProductionExceptionHandler extends Configurable {
     ProductionExceptionHandlerResponse handle(final ProducerRecord<byte[], byte[]> record,
                                               final Exception exception);
 
+    /**
+     * Handles serialization exception and determine if the process should continue. The default implementation is to
+     * fail the process.
+     *
+     * @param record        the record that failed to serialize
+     * @param exception     the exception that occurred during serialization
+     */
+    default ProductionExceptionHandlerResponse onSerializationException(final ProducerRecord record,

Review Comment:
   for the naming I'll change it back to the original kip's spec.  The only reason I would alter the kip is the exception type, it seems too loose as the name suggests it only handles the serialization exception.  But do you think it is necessary?



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] philipnee commented on a diff in pull request #13477: KAFKA-7499: Handle serialization error in ProductionExceptionHandler

Posted by "philipnee (via GitHub)" <gi...@apache.org>.
philipnee commented on code in PR #13477:
URL: https://github.com/apache/kafka/pull/13477#discussion_r1163228427


##########
streams/src/main/java/org/apache/kafka/streams/errors/ProductionExceptionHandler.java:
##########
@@ -34,6 +34,18 @@ public interface ProductionExceptionHandler extends Configurable {
     ProductionExceptionHandlerResponse handle(final ProducerRecord<byte[], byte[]> record,
                                               final Exception exception);
 
+    /**
+     * Handles serialization exception and determine if the process should continue. The default implementation is to
+     * fail the process.
+     *
+     * @param record        the record that failed to serialize
+     * @param exception     the exception that occurred during serialization
+     */
+    default ProductionExceptionHandlerResponse onSerializationException(final ProducerRecord record,
+                                                                        final Exception exception) {

Review Comment:
   maybe the exception should just be SerializationException



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] philipnee commented on a diff in pull request #13477: KAFKA-7499: Handle serialization error in ProductionExceptionHandler

Posted by "philipnee (via GitHub)" <gi...@apache.org>.
philipnee commented on code in PR #13477:
URL: https://github.com/apache/kafka/pull/13477#discussion_r1167095917


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/RecordCollectorImpl.java:
##########
@@ -212,11 +212,11 @@ public <K, V> void send(final String topic,
                     keyClass,
                     valueClass),
                 exception);
-        } catch (final SerializationException exception) {
+        } catch (final Exception exception) {

Review Comment:
   Not sure what you mean by this? Can you elaborate? If the handler itself fail, we throw. If the handler returns FAIL we also re-throw the exception (just wrapped as StreamsException). If the handler return CONTINUE we log a WARN and continue (via return).
   
   thanks that's exactly what I meant/trying to ask.  sorry about not being clear.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] philipnee commented on a diff in pull request #13477: KAFKA-7499: Handle serialization error in ProductionExceptionHandler

Posted by "philipnee (via GitHub)" <gi...@apache.org>.
philipnee commented on code in PR #13477:
URL: https://github.com/apache/kafka/pull/13477#discussion_r1166283763


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/RecordCollectorImpl.java:
##########
@@ -213,6 +212,32 @@ public <K, V> void send(final String topic,
                     keyClass,
                     valueClass),
                 exception);
+        } catch (final SerializationException exception) {
+            final ProducerRecord<K, V> record = new ProducerRecord<>(topic, partition, timestamp, key, value, headers);
+            final ProductionExceptionHandler.ProductionExceptionHandlerResponse response;
+
+            log.debug("Error serializing record to topic {} due to {}", topic, exception);
+
+            try {
+                response = productionExceptionHandler.handleSerializationException(record, exception);
+            } catch (final Exception e) {
+                log.error("Fatal when handling serialization exception", e);
+                recordSendError(topic, e, null);
+                return;
+            }
+
+            if (response == ProductionExceptionHandlerResponse.FAIL) {
+                log.error("Fatal due to SerializationException.", exception);
+                droppedRecordsSensor.record();
+                throw exception;
+            }
+
+            log.warn("Unable to serialize record, continue processing. " +
+                    "ProducerRecord(topic=[{}], partition=[{}], timestamp=[{}])",
+                topic,
+                partition,
+                timestamp);
+

Review Comment:
   might be worth adding a test there actually.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] bbejeck commented on a diff in pull request #13477: KAFKA-7499: Handle serialization error in ProductionExceptionHandler

Posted by "bbejeck (via GitHub)" <gi...@apache.org>.
bbejeck commented on code in PR #13477:
URL: https://github.com/apache/kafka/pull/13477#discussion_r1163377252


##########
streams/src/main/java/org/apache/kafka/streams/errors/ProductionExceptionHandler.java:
##########
@@ -34,6 +34,18 @@ public interface ProductionExceptionHandler extends Configurable {
     ProductionExceptionHandlerResponse handle(final ProducerRecord<byte[], byte[]> record,
                                               final Exception exception);
 
+    /**
+     * Handles serialization exception and determine if the process should continue. The default implementation is to
+     * fail the process.
+     *
+     * @param record        the record that failed to serialize
+     * @param exception     the exception that occurred during serialization
+     */
+    default ProductionExceptionHandlerResponse onSerializationException(final ProducerRecord record,
+                                                                        final Exception exception) {

Review Comment:
   I didn't see this before, but I agree, given it's exclusively for serialization exceptions.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] philipnee commented on pull request #13477: KAFKA-7499: Handle serialization error in ProductionExceptionHandler

Posted by "philipnee (via GitHub)" <gi...@apache.org>.
philipnee commented on PR #13477:
URL: https://github.com/apache/kafka/pull/13477#issuecomment-1489238181

   @mjsax @vvcephei - Can I tag your names here to ask for a review? You reviewed the original PR, so I picked it up from there.


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] bbejeck commented on a diff in pull request #13477: KAFKA-7499: Handle serialization error in ProductionExceptionHandler

Posted by "bbejeck (via GitHub)" <gi...@apache.org>.
bbejeck commented on code in PR #13477:
URL: https://github.com/apache/kafka/pull/13477#discussion_r1163365163


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/RecordCollectorImpl.java:
##########
@@ -213,6 +212,30 @@ public <K, V> void send(final String topic,
                     keyClass,
                     valueClass),
                 exception);
+        } catch (final SerializationException exception) {
+            final ProducerRecord<K, V> record = new ProducerRecord<>(topic, partition, timestamp, key, value, headers);
+            final ProductionExceptionHandler.ProductionExceptionHandlerResponse response;
+            try {
+                response = productionExceptionHandler.onSerializationException(record, exception);
+            } catch (final Exception e) {
+                log.error("Fatal handling serialization exception on record {}", record, e);
+                recordSendError(topic, e, null);
+                return;
+            }
+
+            if (response == ProductionExceptionHandlerResponse.FAIL) {
+                recordSendError(topic, exception, null);

Review Comment:
   The KIP states if the response is `FAIL` streams would add a `log.error` - so I'd add that here.



##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/RecordCollectorTest.java:
##########
@@ -1390,6 +1390,46 @@ public void shouldNotCloseInternalProducerForNonEOS() {
         streamsProducer.flush();
     }
 
+    @Test
+    public void testCollectorFlush_ThrowsStreamsExceptionUsingDefaultExceptionHandler() {
+        final ErrorStringSerializer errorSerializer = new ErrorStringSerializer();
+        final RecordCollector collector = new RecordCollectorImpl(
+            logContext,
+            taskId,
+            streamsProducer,
+            new DefaultProductionExceptionHandler(),
+            streamsMetrics,
+            topology
+        );
+        collector.initialize();
+        collector.send(topic, "key", "val", null, 0, null, stringSerializer, errorSerializer, sinkNodeName, context);
+        assertThrows(StreamsException.class, collector::flush);
+    }
+
+    @Test
+    public void testCollectorFlush_DoesNotThrowStreamsExceptionUsingAlwaysContinueExceptionHandler() {
+        final ErrorStringSerializer errorSerializer = new ErrorStringSerializer();
+        final RecordCollector collector = new RecordCollectorImpl(

Review Comment:
   nit: consider a method to return the `RecordCollector` and pass the exception hander as a parameter here and at line 1396.



##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/RecordCollectorImpl.java:
##########
@@ -213,6 +212,30 @@ public <K, V> void send(final String topic,
                     keyClass,
                     valueClass),
                 exception);
+        } catch (final SerializationException exception) {
+            final ProducerRecord<K, V> record = new ProducerRecord<>(topic, partition, timestamp, key, value, headers);
+            final ProductionExceptionHandler.ProductionExceptionHandlerResponse response;
+            try {
+                response = productionExceptionHandler.handleSerializationException(record, exception);
+            } catch (final Exception e) {
+                log.error("Fatal handling serialization exception on record {}", record, e);
+                recordSendError(topic, e, null);
+                return;
+            }
+
+            if (response == ProductionExceptionHandlerResponse.FAIL) {
+                recordSendError(topic, exception, null);
+                return;
+            }
+
+            log.info("Unable to serialize {}. Continue processing. " +

Review Comment:
   Good point. The KIP states if the response is `CONTINUE` that, streams will log at the `WARN` level, so I agree with your question and suggest changing it to `WARN`



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] philipnee commented on pull request #13477: KAFKA-7499: Handle serialization error in ProductionExceptionHandler

Posted by "philipnee (via GitHub)" <gi...@apache.org>.
philipnee commented on PR #13477:
URL: https://github.com/apache/kafka/pull/13477#issuecomment-1504326949

   @bbejeck - Thanks for the comments, I pushed out a commit with to address the changes you suggested.


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] philipnee commented on pull request #13477: KAFKA-7499: Handle serialization error in ProductionExceptionHandler

Posted by "philipnee (via GitHub)" <gi...@apache.org>.
philipnee commented on PR #13477:
URL: https://github.com/apache/kafka/pull/13477#issuecomment-1505978765

   @bbejeck and @mjsax - thanks for the reviews. I believe I saw something about the class casting handling but I couldn't see that in the comments.  I believe that is already implemented some time ago.


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] philipnee commented on a diff in pull request #13477: KAFKA-7499: Handle serialization error in ProductionExceptionHandler

Posted by "philipnee (via GitHub)" <gi...@apache.org>.
philipnee commented on code in PR #13477:
URL: https://github.com/apache/kafka/pull/13477#discussion_r1167062912


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/RecordCollectorImpl.java:
##########
@@ -212,11 +212,11 @@ public <K, V> void send(final String topic,
                     keyClass,
                     valueClass),
                 exception);
-        } catch (final SerializationException exception) {
+        } catch (final Exception exception) {

Review Comment:
   @mjsax - I guess the intention is to catch all other errors during serialization, not just the serialization exception. I think this is fine, I don't know if there are exceptions but I guess not: seems like the handler should either indicating there's an error and rethrow or continue.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] mjsax commented on a diff in pull request #13477: KAFKA-7499: Handle serialization error in ProductionExceptionHandler

Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #13477:
URL: https://github.com/apache/kafka/pull/13477#discussion_r1163683492


##########
streams/src/main/java/org/apache/kafka/streams/errors/ProductionExceptionHandler.java:
##########
@@ -34,6 +35,18 @@ public interface ProductionExceptionHandler extends Configurable {
     ProductionExceptionHandlerResponse handle(final ProducerRecord<byte[], byte[]> record,
                                               final Exception exception);
 
+    /**
+     * Handles serialization exception and determine if the process should continue. The default implementation is to
+     * fail the process.
+     *
+     * @param record        the record that failed to serialize
+     * @param exception     the exception that occurred during serialization
+     */
+    default ProductionExceptionHandlerResponse onSerializationException(final ProducerRecord record,

Review Comment:
   The KIP say that we would add
   ```
   handleSerializationException(ProducerRecord record, Exception exception); 
   ```
   
   We need to stick to the KIP, or alter the KIP. But why would we need to alter the KIP?



##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/RecordCollectorImpl.java:
##########
@@ -213,6 +212,31 @@ public <K, V> void send(final String topic,
                     keyClass,
                     valueClass),
                 exception);
+        } catch (final SerializationException exception) {
+            final ProducerRecord<K, V> record = new ProducerRecord<>(topic, partition, timestamp, key, value, headers);
+            final ProductionExceptionHandler.ProductionExceptionHandlerResponse response;
+            try {
+                response = productionExceptionHandler.onSerializationException(record, exception);
+            } catch (final Exception e) {
+                log.error("Fatal handling serialization exception on record {}", record, e);
+                recordSendError(topic, e, null);
+                return;
+            }
+
+            if (response == ProductionExceptionHandlerResponse.FAIL) {
+                log.error("Fatal handling serialization exception on record {}", record, exception);
+                recordSendError(topic, exception, null);
+                return;
+            }
+
+            log.warn("Unable to serialize {}. Continue processing. " +
+                    "ProducerRecord(key=[{}], value=[{}], topic=[{}], partition=[{}], timestamp=[{}])",
+                keyBytes == null ? "key" : "value",

Review Comment:
   Even if `keyBytes` is `null`, it's not clear if key or value failed -- the key could have been `null`.



##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/RecordCollectorImpl.java:
##########
@@ -213,6 +212,31 @@ public <K, V> void send(final String topic,
                     keyClass,
                     valueClass),
                 exception);
+        } catch (final SerializationException exception) {
+            final ProducerRecord<K, V> record = new ProducerRecord<>(topic, partition, timestamp, key, value, headers);
+            final ProductionExceptionHandler.ProductionExceptionHandlerResponse response;
+            try {
+                response = productionExceptionHandler.onSerializationException(record, exception);
+            } catch (final Exception e) {
+                log.error("Fatal handling serialization exception on record {}", record, e);
+                recordSendError(topic, e, null);
+                return;
+            }
+
+            if (response == ProductionExceptionHandlerResponse.FAIL) {
+                log.error("Fatal handling serialization exception on record {}", record, exception);
+                recordSendError(topic, exception, null);
+                return;
+            }
+
+            log.warn("Unable to serialize {}. Continue processing. " +
+                    "ProducerRecord(key=[{}], value=[{}], topic=[{}], partition=[{}], timestamp=[{}])",

Review Comment:
   As above -- we should not log key/value.



##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/RecordCollectorImpl.java:
##########
@@ -213,6 +212,31 @@ public <K, V> void send(final String topic,
                     keyClass,
                     valueClass),
                 exception);
+        } catch (final SerializationException exception) {
+            final ProducerRecord<K, V> record = new ProducerRecord<>(topic, partition, timestamp, key, value, headers);
+            final ProductionExceptionHandler.ProductionExceptionHandlerResponse response;
+            try {
+                response = productionExceptionHandler.onSerializationException(record, exception);
+            } catch (final Exception e) {
+                log.error("Fatal handling serialization exception on record {}", record, e);

Review Comment:
   We should never log `record` (maybe except for TRACE level), because it might leak data and is a security concern.



##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/RecordCollectorImpl.java:
##########
@@ -213,6 +212,31 @@ public <K, V> void send(final String topic,
                     keyClass,
                     valueClass),
                 exception);
+        } catch (final SerializationException exception) {
+            final ProducerRecord<K, V> record = new ProducerRecord<>(topic, partition, timestamp, key, value, headers);
+            final ProductionExceptionHandler.ProductionExceptionHandlerResponse response;
+            try {
+                response = productionExceptionHandler.onSerializationException(record, exception);
+            } catch (final Exception e) {
+                log.error("Fatal handling serialization exception on record {}", record, e);
+                recordSendError(topic, e, null);
+                return;
+            }
+
+            if (response == ProductionExceptionHandlerResponse.FAIL) {
+                log.error("Fatal handling serialization exception on record {}", record, exception);

Review Comment:
   As above



##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/RecordCollectorImpl.java:
##########
@@ -213,6 +212,30 @@ public <K, V> void send(final String topic,
                     keyClass,
                     valueClass),
                 exception);
+        } catch (final SerializationException exception) {
+            final ProducerRecord<K, V> record = new ProducerRecord<>(topic, partition, timestamp, key, value, headers);
+            final ProductionExceptionHandler.ProductionExceptionHandlerResponse response;
+            try {
+                response = productionExceptionHandler.onSerializationException(record, exception);
+            } catch (final Exception e) {
+                log.error("Fatal handling serialization exception on record {}", record, e);
+                recordSendError(topic, e, null);
+                return;
+            }
+
+            if (response == ProductionExceptionHandlerResponse.FAIL) {
+                recordSendError(topic, exception, null);

Review Comment:
   Instead of calling `recordSendError` should we just re-throw directly -- otherwise, we might double log and worse actually even call `handle(...)` and it would be very confusing to call the handler (even if two different methods) twice for the same error, and even worse, the handler could not change it's mind and return `CONTINUE` on the second call.



##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/RecordCollectorImpl.java:
##########
@@ -213,6 +212,31 @@ public <K, V> void send(final String topic,
                     keyClass,
                     valueClass),
                 exception);
+        } catch (final SerializationException exception) {
+            final ProducerRecord<K, V> record = new ProducerRecord<>(topic, partition, timestamp, key, value, headers);
+            final ProductionExceptionHandler.ProductionExceptionHandlerResponse response;
+            try {
+                response = productionExceptionHandler.onSerializationException(record, exception);
+            } catch (final Exception e) {
+                log.error("Fatal handling serialization exception on record {}", record, e);
+                recordSendError(topic, e, null);
+                return;
+            }
+
+            if (response == ProductionExceptionHandlerResponse.FAIL) {
+                log.error("Fatal handling serialization exception on record {}", record, exception);
+                recordSendError(topic, exception, null);
+                return;
+            }

Review Comment:
   We should also record if we drop a record via `droppedRecordsSensor.record()` (cf `recordSendError(...)`)



##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/RecordCollectorImpl.java:
##########
@@ -213,6 +212,31 @@ public <K, V> void send(final String topic,
                     keyClass,
                     valueClass),
                 exception);
+        } catch (final SerializationException exception) {
+            final ProducerRecord<K, V> record = new ProducerRecord<>(topic, partition, timestamp, key, value, headers);
+            final ProductionExceptionHandler.ProductionExceptionHandlerResponse response;
+            try {
+                response = productionExceptionHandler.onSerializationException(record, exception);
+            } catch (final Exception e) {
+                log.error("Fatal handling serialization exception on record {}", record, e);

Review Comment:
   Seems we don't log the original `exception` for this case, what could be a problem. Seem we might log it at least at DEBUG level?



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] kamalcph commented on pull request #13477: KAFKA-7499: Handle serialization error in ProductionExceptionHandler

Posted by "kamalcph (via GitHub)" <gi...@apache.org>.
kamalcph commented on PR #13477:
URL: https://github.com/apache/kafka/pull/13477#issuecomment-1508210519

   Thanks @philipnee for taking this forward!


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] mjsax commented on a diff in pull request #13477: KAFKA-7499: Handle serialization error in ProductionExceptionHandler

Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #13477:
URL: https://github.com/apache/kafka/pull/13477#discussion_r1167091288


##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/RecordCollectorTest.java:
##########
@@ -1391,21 +1390,57 @@ public void shouldNotCloseInternalProducerForNonEOS() {
     }
 
     @Test
-    public void testCollectorFlush_ThrowsStreamsExceptionUsingDefaultExceptionHandler() {
-        final ErrorStringSerializer errorSerializer = new ErrorStringSerializer();
-        final RecordCollector collector = newRecordCollector(new DefaultProductionExceptionHandler());
-        collector.initialize();
-        collector.send(topic, "key", "val", null, 0, null, stringSerializer, errorSerializer, sinkNodeName, context);
-        assertThrows(StreamsException.class, collector::flush);
+    public void shouldThrowStreamsExceptionUsingDefaultExceptionHandler() {
+        try (final ErrorStringSerializer errorSerializer = new ErrorStringSerializer()) {
+            final RecordCollector collector = newRecordCollector(new DefaultProductionExceptionHandler());
+            collector.initialize();
+
+            final StreamsException error = assertThrows(
+                StreamsException.class,
+                () -> collector.send(topic, "key", "val", null, 0, null, stringSerializer, errorSerializer, sinkNodeName, context)
+            );
+
+            assertThat(error.getCause(), instanceOf(SerializationException.class));
+        }
     }
 
     @Test
-    public void testCollectorFlush_DoesNotThrowStreamsExceptionUsingAlwaysContinueExceptionHandler() {
-        final ErrorStringSerializer errorSerializer = new ErrorStringSerializer();
-        final RecordCollector collector = newRecordCollector(new AlwaysContinueProductionExceptionHandler());
-        collector.initialize();
-        collector.send(topic, "key", "val", null, 0, null, errorSerializer, stringSerializer, sinkNodeName, context);
-        assertDoesNotThrow(collector::flush);
+    public void shouldDropRecordExceptionUsingAlwaysContinueExceptionHandler() {
+        try (final ErrorStringSerializer errorSerializer = new ErrorStringSerializer()) {
+            final RecordCollector collector = newRecordCollector(new AlwaysContinueProductionExceptionHandler());
+            collector.initialize();
+
+            collector.send(topic, "key", "val", null, 0, null, errorSerializer, stringSerializer, sinkNodeName, context);
+
+            assertThat(mockProducer.history().isEmpty(), equalTo(true));
+            assertThat(
+                streamsMetrics.metrics().get(new MetricName(
+                    "dropped-records-total",
+                    "stream-task-metrics",
+                    "The total number of dropped records",
+                    mkMap(
+                        mkEntry("thread-id", Thread.currentThread().getName()),
+                        mkEntry("task-id", taskId.toString())
+                    ))).metricValue(),
+                equalTo(1.0)
+            );
+        }
+    }
+
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    @Test
+    public void shouldNotCallProductionExceptionHandlerOnClassCastException() {
+        try (final ErrorStringSerializer errorSerializer = new ErrorStringSerializer()) {
+            final RecordCollector collector = newRecordCollector(new AlwaysContinueProductionExceptionHandler());
+            collector.initialize();
+

Review Comment:
   Good idea. Wanna do a small follow-up PR adding the check? Should just be a one-liner.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] philipnee commented on a diff in pull request #13477: KAFKA-7499: Handle serialization error in ProductionExceptionHandler

Posted by "philipnee (via GitHub)" <gi...@apache.org>.
philipnee commented on code in PR #13477:
URL: https://github.com/apache/kafka/pull/13477#discussion_r1167075145


##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/RecordCollectorTest.java:
##########
@@ -1391,21 +1390,57 @@ public void shouldNotCloseInternalProducerForNonEOS() {
     }
 
     @Test
-    public void testCollectorFlush_ThrowsStreamsExceptionUsingDefaultExceptionHandler() {
-        final ErrorStringSerializer errorSerializer = new ErrorStringSerializer();
-        final RecordCollector collector = newRecordCollector(new DefaultProductionExceptionHandler());
-        collector.initialize();
-        collector.send(topic, "key", "val", null, 0, null, stringSerializer, errorSerializer, sinkNodeName, context);
-        assertThrows(StreamsException.class, collector::flush);
+    public void shouldThrowStreamsExceptionUsingDefaultExceptionHandler() {
+        try (final ErrorStringSerializer errorSerializer = new ErrorStringSerializer()) {
+            final RecordCollector collector = newRecordCollector(new DefaultProductionExceptionHandler());
+            collector.initialize();
+
+            final StreamsException error = assertThrows(
+                StreamsException.class,
+                () -> collector.send(topic, "key", "val", null, 0, null, stringSerializer, errorSerializer, sinkNodeName, context)
+            );
+
+            assertThat(error.getCause(), instanceOf(SerializationException.class));
+        }
     }
 
     @Test
-    public void testCollectorFlush_DoesNotThrowStreamsExceptionUsingAlwaysContinueExceptionHandler() {
-        final ErrorStringSerializer errorSerializer = new ErrorStringSerializer();
-        final RecordCollector collector = newRecordCollector(new AlwaysContinueProductionExceptionHandler());
-        collector.initialize();
-        collector.send(topic, "key", "val", null, 0, null, errorSerializer, stringSerializer, sinkNodeName, context);
-        assertDoesNotThrow(collector::flush);
+    public void shouldDropRecordExceptionUsingAlwaysContinueExceptionHandler() {
+        try (final ErrorStringSerializer errorSerializer = new ErrorStringSerializer()) {
+            final RecordCollector collector = newRecordCollector(new AlwaysContinueProductionExceptionHandler());
+            collector.initialize();
+
+            collector.send(topic, "key", "val", null, 0, null, errorSerializer, stringSerializer, sinkNodeName, context);
+
+            assertThat(mockProducer.history().isEmpty(), equalTo(true));
+            assertThat(
+                streamsMetrics.metrics().get(new MetricName(
+                    "dropped-records-total",
+                    "stream-task-metrics",
+                    "The total number of dropped records",
+                    mkMap(
+                        mkEntry("thread-id", Thread.currentThread().getName()),
+                        mkEntry("task-id", taskId.toString())
+                    ))).metricValue(),
+                equalTo(1.0)
+            );
+        }
+    }
+
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    @Test
+    public void shouldNotCallProductionExceptionHandlerOnClassCastException() {
+        try (final ErrorStringSerializer errorSerializer = new ErrorStringSerializer()) {
+            final RecordCollector collector = newRecordCollector(new AlwaysContinueProductionExceptionHandler());
+            collector.initialize();
+

Review Comment:
   i think we should also verify there's no send here.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] mjsax commented on a diff in pull request #13477: KAFKA-7499: Handle serialization error in ProductionExceptionHandler

Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #13477:
URL: https://github.com/apache/kafka/pull/13477#discussion_r1163702670


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/RecordCollectorImpl.java:
##########
@@ -213,6 +212,31 @@ public <K, V> void send(final String topic,
                     keyClass,
                     valueClass),
                 exception);
+        } catch (final SerializationException exception) {

Review Comment:
   As pointed out during the KIP discussion, the new handler should also cover `ClassCastException` -- we only had a special catch-block for it, to get a better error message (we still want a good error message for this case, but we should also apply the handler and allow people to CONTINUE on a ClassCastException).



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] mjsax commented on a diff in pull request #13477: KAFKA-7499: Handle serialization error in ProductionExceptionHandler

Posted by "mjsax (via GitHub)" <gi...@apache.org>.
mjsax commented on code in PR #13477:
URL: https://github.com/apache/kafka/pull/13477#discussion_r1166218023


##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/RecordCollectorImpl.java:
##########
@@ -213,6 +212,32 @@ public <K, V> void send(final String topic,
                     keyClass,
                     valueClass),
                 exception);
+        } catch (final SerializationException exception) {
+            final ProducerRecord<K, V> record = new ProducerRecord<>(topic, partition, timestamp, key, value, headers);
+            final ProductionExceptionHandler.ProductionExceptionHandlerResponse response;
+
+            log.debug("Error serializing record to topic {} due to {}", topic, exception);
+
+            try {
+                response = productionExceptionHandler.handleSerializationException(record, exception);
+            } catch (final Exception e) {
+                log.error("Fatal when handling serialization exception", e);
+                recordSendError(topic, e, null);
+                return;
+            }
+
+            if (response == ProductionExceptionHandlerResponse.FAIL) {
+                log.error("Fatal due to SerializationException.", exception);
+                droppedRecordsSensor.record();
+                throw exception;
+            }
+
+            log.warn("Unable to serialize record, continue processing. " +
+                    "ProducerRecord(topic=[{}], partition=[{}], timestamp=[{}])",
+                topic,
+                partition,
+                timestamp);
+

Review Comment:
   Just realizing that a `return` is missing here -- without `return` we would still call `streamsProducer.send` passing in `key == null` and `value == null` but we should not send anything...
   
   I can push a fix into this PR (including extending the tests for it) and merge afterwards.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org