[Quickfix-developers] file descriptor/memory leak in ThreadedSocketInitiator
Brought to you by:
orenmnero
|
From: Alex S. <al...@ya...> - 2007-01-08 14:49:18
|
Hi,
We left our application running over the holidays
continuously trying to reconnect to a server and
failing. When we came back, the whole server seemed to
be broken. All applications were failing because they
could not allocate any file descriptors from the OS
(Windows Server 2003)
Windows has a limit on the number of open file
descriptors including open sockets.
It turned out that quickfix fails to clean up sockets
when connections fail. With 7 connections failing
every 30 seconds, the limit was reached over a few
days.
The open sockets also use up memory.
The problem is in here:
bool ThreadedSocketInitiator::doConnect( const
SessionID& s, const Dictionary& d )
{ QF_STACK_PUSH(ThreadedSocketInitiator::doConnect)
try
{
Session* session = Session::lookupSession( s );
if( !session->isSessionTime() ) return false;
std::string address;
short port = 0;
getHost( s, d, address, port );
Log* log = session->getLog();
log->onEvent( "Connecting to " + address + " on
port " + IntConvertor::convert((unsigned short)port)
);
int socket = socket_createConnector();
if( socket_connect(socket, address.c_str(), port)
< 0 )
{
log->onEvent( "Connection failed" );
//!!!! Socket never closed because it is closed in
ThreadedSocketConnection::disconnect
return false;
}
log->onEvent( "Connection succeeded" );
ThreadedSocketConnection* pConnection =
new ThreadedSocketConnection( s, socket,
getApplication(), *this );
ThreadPair* pair = new ThreadPair( this,
pConnection );
{
Locker l( m_mutex );
unsigned thread;
if ( !thread_spawn( &socketThread, pair, thread
) )
delete pair;
addThread( socket, thread );
}
return true;
}
catch ( std::exception& ) { return false; }
QF_STACK_POP
}
Alex
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
|