You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Ralph Goers (Jira)" <ji...@apache.org> on 2022/09/08 05:45:00 UTC

[jira] [Commented] (LOG4J2-3517) Log4j2 logging Tools TcpSocketServer socket leak - tcp socket server does not close sockets properly and they stay in CLOSE_WAIT state

    [ https://issues.apache.org/jira/browse/LOG4J2-3517?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17601639#comment-17601639 ] 

Ralph Goers commented on LOG4J2-3517:
-------------------------------------

Please feel free to submit a PR for that repo. Keep in mind that we treat the TcpSocketServer as a sample, which is why it isn't included in releases.

> Log4j2 logging Tools TcpSocketServer socket leak - tcp socket server does not close sockets properly and they stay in CLOSE_WAIT state
> --------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: LOG4J2-3517
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3517
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Servers
>    Affects Versions: 2.17.2
>         Environment: Linux machine:
> uname -a
> Linux  4.18.0-193.13.2.el8_2.x86_64 #1 SMP Mon Jul 13 23:17:28 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
>  
>  java -version
> openjdk version "1.8.0_262"
> OpenJDK Runtime Environment (build 1.8.0_262-b10)
> OpenJDK 64-Bit Server VM (build 25.262-b10, mixed mode)
>            Reporter: E E
>            Priority: Major
>
> We are using the tcp socket server for listening and intercepting log4j2 logging events from clients and logging them
> We have close wait sockets on our server where the log4j2 tcp socket server is running after connection is closed by the client, the client crashed and connection terminated by the client.
> Looks like a bug in TcpSocketServer --> SocketHandler --> that in case of EOF exception like if a connection is closed by the client or connection terminated un expectedly then the connection is not closed properly and the socket remains in close wait state forever or until the tcp socket server is restarted.
> This is a socket leak and after sometime with many close wait sockets the machine can be unresponsive and can deny new connections if max open files is reached.
> Looking at the source code of TcpSocketServer --> SocketHandler --> in the run() method, if EOF exception the closed turned to true and the input stream is not properly closed:
>         @Override
>         public void run() {
>             final EntryMessage entry = logger.traceEntry();
>             boolean closed = false;
>             try {
>                 try {
>                     while (!shutdown) {
>                         logEventInput.logEvents(inputStream, TcpSocketServer.this);
>                     }
> {color:#FF0000}                *} catch (final EOFException e) {*{color}
>                     *{color:#FF0000}closed = true;{color}*
> {color:#FF0000}                *}* {color}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);
>                 } catch (ParseException e) {
>                     logger.error("ParseException encountered while reading from socket", e);
>                 }
> {color:#FF0000}                *if (!closed) {*{color}
> {color:#FF0000}                    *Closer.closeSilently(inputStream);*{color}
> {color:#FF0000}                *}*{color}
>             } finally {
>                 handlers.remove(Long.valueOf(getId()));
>             }
>             logger.traceExit(entry);
>         }
>  
> Thank you



--
This message was sent by Atlassian Jira
(v8.20.10#820010)