# ProductionExceptionHandler in infinite loop for Kafka stream with exactly once enabled

**URL:** <https://forum.confluent.io/t/productionexceptionhandler-in-infinite-loop-for-kafka-stream-with-exactly-once-enabled/8887>\
**Category:** Kafka Streams\
**Created:** [17 October 2023 06:00 UTC](https://forum.confluent.io/t/productionexceptionhandler-in-infinite-loop-for-kafka-stream-with-exactly-once-enabled/8887 "2023-10-17T06:00:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karolina](https://avatars.discourse-cdn.com/v4/letter/k/c68b51/32.png) [@Karolina](https://forum.confluent.io/u/Karolina)\
**Post date:** [17 October 2023 06:00 UTC](https://forum.confluent.io/t/productionexceptionhandler-in-infinite-loop-for-kafka-stream-with-exactly-once-enabled/8887/1 "2023-10-17T06:00:15Z")

</div>

I have an aplication written in kotlin and I use one quiet straightforward Kafka stream inside.

I provided ProductionExceptionHandler and UncaughtExceptionHandler because I do not want the service to crash. Inside both of them I log the exception and then from the first handler I return ProductionExceptionHandlerResponse.CONTINUE, and from the second one StreamThreadExceptionResponse.REPLEACE\_THREAD.

I have a test where I force the stream to throw RecordTooLargeException, it is thrown correctly and ProductionExceptionHandler is involved in handling that one.

The problem is: Service goes into an infinite loop and tries to send the problematic message again and again.

Can I somehow skip that message? The transaction of course is never commited. It tries to end that one.

---

<div class="post-metadata">

**Author:** ![mjsax](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/mjsax/32/3113_2.png) [@mjsax](https://forum.confluent.io/u/mjsax)\
**Post date:** [18 October 2023 02:30 UTC](https://forum.confluent.io/t/productionexceptionhandler-in-infinite-loop-for-kafka-stream-with-exactly-once-enabled/8887/2 "2023-10-18T02:30:56Z")

</div>

I believe you are hitting [[KAFKA-15259] Kafka Streams does not continue processing due to rollback despite ProductionExceptionHandlerResponse.CONTINUE if using exactly\_once - ASF JIRA](https://issues.apache.org/jira/browse/KAFKA-15259)

It’s actually a change in how the producer works, that “breaks” Kafka Streams. Details are on the ticket.

The only workaround I can think of (for `RecordTooLargeException`), it so add a explicit step into your KS program, that serialized the data, and checks the size, and drops the record is too big before it hits the sink. – Of course, if there would be some other exception this workaround would not be sufficient.
