Skip to content

XMLSocketAppender file descriptors remain open upon unsuccessful connect #3211

@danielpetri

Description

@danielpetri

Description

Log4cxx 1.1.0 (default available on Ubuntu 24.04) does not close file descriptors when the log server, e.g., chainsaw is not running. The counting number of sockets remain open.

Code example:

#include <memory>
#include <log4cxx/patternlayout.h>
#include <log4cxx/net/xmlsocketappender.h>
#include <thread>

int main( int argc, char *argv[] )
{
    auto logger = log4cxx::Logger::getRootLogger( );
    auto appender = std::make_shared<log4cxx::net::XMLSocketAppender>( "localhost", 1234 );
    auto layout =
        std::make_shared<log4cxx::PatternLayout>( LOG4CXX_STR( "[%-4p] (%F:%L) %d{mm:ss,SSS} %X{application} %m%n" ) );
    appender->setLayout( layout );
    log4cxx::helpers::Pool pool;
    appender->activateOptions( pool );
    logger->addAppender( appender );
    logger->setLevel( log4cxx::Level::getInfo( ) );

    while ( true )
    {
        LOG4CXX_ERROR( logger, "Something went wrong" );
        LOG4CXX_INFO( logger, "Very important information" );
        std::this_thread::sleep_for( std::chrono::seconds( 1 ) );
    }

    return 0;
}

Listing and counting the open file descriptors periodically results in a constantly growing number:

# ls -l /proc/$(pidof log4cxxdemo)/fd | wc -l
123
# sleep 600
# ls -l /proc/$(pidof log4cxxdemo)/fd | wc -l
141

The socket should be closed after connection failures.

Configuration

Version: [Log4cxx 1.1.0]

Operating system: [Linux, Ubuntu 24.04]

Logs

Program output

log4cxx: Could not connect to [localhost:1234]. We will try again in 30000 ms
log4cxx: IO Exception : status code = 111(Connection refused)

Reproduction

Compile the code above and link with log4cxx library, then execute.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions