Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-2388

Thread indefinitely blocked when logging a message in an interrupted thread

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • None
    • 2.11.1, 3.0.0
    • Flume Appender
    • None

    Description

      Logging a message to the Flume appender in an interrupted thread undefinitely block the thread.

      The thread is blocked in an infinite loop here :

      org.apache.logging.log4j.flume.appender.FlumePersistentManager.send(Event) :

       

      boolean interrupted = false;
      int ieCount = 0;
      do {
          try {
              future.get();
          } catch (final InterruptedException ie) {
              interrupted = true;
              ++ieCount;
          }
      } while (interrupted && ieCount <= 1);
      

       

      This test case allows to reproduce the problem (add the code below in FlumePersistentAppenderTest in log4j-flume-ng module):

          @Test
          public void testLogInterrupted() {
              ExecutorService executor = Executors.newSingleThreadExecutor();
              executor.execute(() -> {
                  executor.shutdownNow();
                  final Logger logger = LogManager.getLogger("EventLogger");
                  final Marker marker = MarkerManager.getMarker("EVENT");
                  logger.info(marker, "This is a test message");
                  Assert.assertTrue("Interruption status not preserved",
                          Thread.currentThread().isInterrupted());
              });
          }
      

       

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              failled Failled
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: