Kohei Tamura created LOG4J2-1922:
------------------------------------

             Summary: SocketHandler leaks connection if EOFException is thrown
                 Key: LOG4J2-1922
                 URL: https://issues.apache.org/jira/browse/LOG4J2-1922
             Project: Log4j 2
          Issue Type: Bug
          Components: Core
    Affects Versions: 2.7
            Reporter: Kohei Tamura


SocketHandler should close the input stream in the finally block.

{code:title=TcpSocketServer.java|borderStyle=solid}
    /**
     * Thread that processes the events.
     */
    private class SocketHandler extends Thread {

        private final T inputStream;

        private volatile boolean shutdown = false;

        public SocketHandler(final Socket socket) throws IOException {
            this.inputStream = 
logEventInput.wrapStream(socket.getInputStream());
        }

        @Override
        public void run() {
            boolean closed = false;
            try {
                try {
                    while (!shutdown) {
                        logEventInput.logEvents(inputStream, 
TcpSocketServer.this);
                    }
                } catch (final EOFException e) {
                    closed = true;
                } catch (final OptionalDataException e) {
                    logger.error("OptionalDataException eof=" + e.eof + " 
length=" + e.length, e);
                } catch (final IOException e) {
                    logger.error("IOException encountered while reading from 
socket", e);
                }
                if (!closed) {
                    try {
                        inputStream.close();
                    } catch (final Exception ex) {
                        // Ignore the exception;
                    }
                }
            } finally {
                handlers.remove(Long.valueOf(getId()));
            }
        }

        public void shutdown() {
            this.shutdown = true;
            interrupt();
        }
    }
{code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to