Fix KafkaAppender reporting error after successful retry#4125
Fix KafkaAppender reporting error after successful retry#4125SebTardif wants to merge 3 commits into
Conversation
ramanathan1504
left a comment
There was a problem hiding this comment.
LGTM overall — great fix for the break/return retry behavior, and thanks for adding DEBUG logging plus cleaning up getRetryCount().
One small suggestion commented to keep the diff minimal: retain the existing while loop shape and just apply the early return + DEBUG logging inside it.
When retryCount is configured and the initial tryAppend() fails, the retry loop uses break to exit on success. However, break only exits the while loop and execution always reaches the error() call afterward. This causes spurious error notifications for transient Kafka failures that were successfully recovered by a retry. Replace break with return so that a successful retry exits append() without reporting an error. Retry exceptions are now logged at DEBUG level for diagnostics instead of being silently discarded. Also remove dead code in Builder.getRetryCount() where Integer.valueOf(int) was wrapped in a NumberFormatException catch that can never fire. The bug was introduced in apache#315. Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
42bc3fe to
2871852
Compare
|
Hi @SebTardif , Thank you so much for your patience and for contributing to this! We really appreciate the time and effort you've put into getting this Before we can finally merge this, there are just a few quick administrative things we need to address:
Next Steps: Thanks again for your great work on this! |
|
Great guidance @ramanathan1504! 💯
@ramanathan1504, @SebTardif, we've dropped the requirement for commit signatures — see #3989. You can skip that chore. |
Adopt reviewer suggestion to use try-with-resources CloseableThreadContext instead of manual ThreadContext.put/clearMap.
|
Thanks @ramanathan1504 for the review guidance and @vy for clarifying on signatures. Adopted |
Fix KafkaAppender retry logic that always reports an error to the error handler even when a retry succeeds.
When
retryCountis configured and the initialtryAppend()fails, the retry loop usesbreakto exit on success. However,breakonly exits thewhileloop; execution always reaches theerror()call afterward. This causes spurious error notifications for transient Kafka failures that were successfully recovered by a retry.This change replaces
breakwithreturnso that a successful retry exitsappend()without reporting an error. Retry exceptions are now logged at DEBUG level for diagnostics instead of being silently discarded.Also removes dead code in
Builder.getRetryCount()whereInteger.valueOf(int)was wrapped in aNumberFormatExceptioncatch that can never fire.The bug was introduced in #315.
Checklist
2.xbranch if you are targeting Log4j 2; usemainotherwise./mvnw verifysucceeds (the build instructions)