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

Deadlock with SocketAppender

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Critical
    • Resolution: Fixed
    • 2.0-beta4
    • 2.0-beta5
    • Appenders
    • None

    Description

      We found a Deadlock in the SocketAppender (TCPSocketManager.java), when the reconnectionDelay is used.
      A JUnit-Testcase (testTcpAppenderDeadlock()) has been attached, which reproduced the deadlock.

      Description of the JUnit-Testcase:
      • No SocketServer is startet
      • We generate a SocketAppender with a reconnectionDelay= 10sec
      • The SocketAppender acknowledges that no SocktServer is there, and start the timeout
      • During reconnectionDelay the SocketServer started and something is logged
      • Now the user-thread (here the JUNIT-Thread) and the Reconnector-Thread are blocking each other forever

      An additional Issue occurs:
      If no SocketServer is available at the start of the SocketAppender, each user-thread is blocked at every logging operation up to the defined reconnection-time!

      Recommended solution:
      TCPSocketManager.java
      @Override
      protected synchronized void write(final byte[] bytes, final int offset, final int length) {
      // if (socket == null) {
      // if (connector != null)

      { // connector.latch(); // }

      // if (socket == null)

      { // final String msg = "Error writing to " + getName() + " socket not available"; // throw new AppenderRuntimeException(msg); // }

      // }
      if (socket == null) {
      if (connector != null)

      { return; }

      else

      { final String msg = "Error writing to " + getName() + " socket not available"; throw new AppenderRuntimeException(msg); }

      }

      Attachments

        1. SocketAppenderTest.java
          8 kB
          Werner

        Activity

          People

            rgoers Ralph Goers
            gow Werner
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: