Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-1382

AsyncAppender#putUninterruptibly may loop forever

    XMLWordPrintable

Details

    • Icon: Task Task
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • 1.2.3
    • logback-core
    • None
    •  

       

       

    Description

      The code in AsyncAppenderBase#putUninterruptibly is suspicious, if InterruptedException is raised in blockingQueue.put(...), the interrupted flag is set to true but as there is a while(true) around the current Thread will not be interrupted, loop forever and the code in the finally block may never occur.

       

      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();
              }
          }
      }
      

      What's the purpose of this infinite loop?

      I suspect the intent was to write while(!interrupted&&!pushed) instead of while(true).

      To me, the blockingQueue.put is a blocking operation, the current thread will wait until it can push the event in the queue. Attempting multiple retries seems useless and dangerous to me. At least the number of retries should be bounded.

      Attachments

        Activity

          People

            logback-dev Logback dev list
            gquintana Gérald Quintana
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: