libmicrohttpd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libmicrohttpd] Connection limit problems


From: Jesse Anderton
Subject: [libmicrohttpd] Connection limit problems
Date: Mon, 5 Apr 2010 10:21:11 -0400

I have a C++ server program which uses libmicrohttpd to expose an HTTP interface for request processing.  I have recently started seeing a problem with the connection pool: although the server appears to be processing requests in a timely fashion, it occasionally enters a state in which all the available connections are used up and none is ever released.  Once the program enters this state, it will stay there until the program is terminated - it has run like this for at least two days.  The only client which currently speaks with it is a Java program I control which should be limiting itself to fewer connections than the server permits, and which should be closing connections which have not been used for 60 seconds.

My question for the group is: might this be due to a bug in libmicrohttpd?  Has anyone seen similar problems?  I would expect the connection timeout I'm setting to prevent this problem from lasting, at least.  Perhaps this suggests that the problem is in my web callback, and that libmicrohttpd never gets a chance to detect the problem and clean up after it?

The error I'm seeing is:

Server reached connection limit (closing inbound connection)

I have configured the web daemon like so:

MHD_start_daemon( MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG
                , port
                , &webClientAuthCallback, this
                , &webCallback, this
                , MHD_OPTION_CONNECTION_LIMIT, 20
                , MHD_OPTION_PER_IP_CONNECTION_LIMIT, 20
                , MHD_OPTION_CONNECTION_TIMEOUT, 630
                , MHD_OPTION_URI_LOG_CALLBACK, uriLogCallback, this
                , MHD_OPTION_EXTERNAL_LOGGER, webErrorCallback, this
                , MHD_OPTION_END
                );

The webCallback() method authenticates, carries out the requested task, and then ends with this code:

// Build the response
struct MHD_Response * mhdResponse;
if( !( mhdResponse = MHD_create_response_from_data( pageContent.length()
        , const_cast<void*>( reinterpret_cast<const void*>( pageContent.c_str() ) ), MHD_YES, MHD_YES ) ) ) {
    return MHD_NO;
}
for( map<string, string>::const_iterator it = headers.begin(); it != headers.end(); ++it ) {
    if( MHD_add_response_header( mhdResponse, it->first.c_str(), it->second.c_str() ) == MHD_NO ) {
        return MHD_NO;
    }
}

// Enqueue and destroy the response
int result = MHD_queue_response( connection, mhdResponseCode, mhdResponse );
MHD_destroy_response( mhdResponse );
return result;

Thanks for your time,

Jesse

reply via email to

[Prev in Thread] Current Thread [Next in Thread]