danielwegener / logback-kafka-appender

Logback appender for Apache Kafka
Apache License 2.0
640 stars 263 forks source link

InterruptedException while stopping Kafka Appender #108

Closed gquintana closed 3 years ago

gquintana commented 3 years ago

Under some specific conditions and error occurs when the application is stopping and the KafkaProducer is still stopping

o.a.k.clients.producer.KafkaProducer     : [Producer clientId=xxx] Interrupted while joining ioThread

java.lang.InterruptedException: null
    at java.base/java.lang.Object.wait(Native Method)
    at java.base/java.lang.Thread.join(Thread.java:1313)
    at org.apache.kafka.clients.producer.KafkaProducer.close(KafkaProducer.java:1199)
    at org.apache.kafka.clients.producer.KafkaProducer.close(KafkaProducer.java:1176)
    at org.apache.kafka.clients.producer.KafkaProducer.close(KafkaProducer.java:1154)
    at com.github.danielwegener.logback.kafka.KafkaAppender.stop(KafkaAppender.java:74)
    at ch.qos.logback.core.spi.AppenderAttachableImpl.detachAndStopAllAppenders(AppenderAttachableImpl.java:107)

I can propose a fix, but I don't know which solution is the best:

  1. Add a close timeout (using producer.close(closeTimeout) methods) to limit the time spend waiting for the producer to stop. The logback-kafka-appender library depends on kafka-clients 1.0.0 which only has a producer.close(long, TimeUnit) which is deprecated and replaced by producer.close(Duration) in recent releases.
  2. Catch and swallow InterruptedException
gquintana commented 3 years ago

Well in fact this log lays in the KafkaProducer