[logback-user] AsyncAppender dropping events when thread is interrupted

Ceki Gülcü ceki at qos.ch
Mon Jan 23 16:29:10 CET 2017


Hi Jacob,

A bug report with a github pull request would be most welcome.

Best regards,

--
Ceki

On 1/23/2017 16:18, Jakob Bergendahl wrote:
> Hi,
>
> As mentioned in a comment on LOGBACK-910, the AsyncAppender will
> silently drop events when the current thread is interrupted. The
> simplest test for this is:
>
>     Thread.currentThread().interrupt();
>     log.warn("message 1"); // This was always dropped
>     log.warn("message 2"); // This is also dropped since LOGBACK-910 was
> fixed
>
> I have recently spent a long time troubleshooting a case where an error
> was sometimes not logged because of this. Have you considered using
> something similar to Guava's Uninterruptibles.putUninterruptibly
> instead, i.e. try to put in a loop while interrupted and reset the
> interrupt status once the put succeeds? Code-wise this would mean
> changing AsyncAppenderBase from:
>
>     private void put(E eventObject) {
>         if (neverBlock) {
>             blockingQueue.offer(eventObject);
>         } else {
>             try {
>                 blockingQueue.put(eventObject);
>             } catch (InterruptedException e) {
>                 // Interruption of current thread when in doAppend
> method should not be consumed
>                 // by AsyncAppender
>         }
>     }
>
> to something like (assuming no Guava dependency):
>
>     private void put(E eventObject) {
>         if (neverBlock) {
>             blockingQueue.offer(eventObject);
>         } else {
>             putUninterruptibly(eventObject);
>         }
>     }
>
>     private void putUninterruptibly(E eventObject) {
>         boolean interrupted = false;
>         try {
>             while (true) {
>                 try {
>                     blockingQueue.put(eventObject);
>                     break;
>                 } catch (InterruptedException e) {
>                     interrupted = true;
>                 }
>             }
>         } finally {
>             if (interrupted) {
>                 Thread.currentThread().interrupt();
>             }
>         }
>     }
>
> Does this make sense? I would be willing to help out with this, but not
> sure what my next step should be.
>
> /Jakob
>
>
> _______________________________________________
> logback-user mailing list
> logback-user at qos.ch
> http://mailman.qos.ch/mailman/listinfo/logback-user
>


More information about the logback-user mailing list