Re: [Quickfix-developers] file descriptor/memory leak in ThreadedSocketInitiator
Brought to you by:
orenmnero
|
From: Alex S. <al...@ya...> - 2007-01-08 14:42:58
|
Hi,
In addition to cleaning up the sockets when connection
fails, my application would also benefit from
receiving a callback when it happens as well.
That way, the app can keep track of failed attempts
and force itself to shutdown after a number of
attempts is reached.
Not being able to establish a connection is different
from not being able to logon. I think that currently
when connections fail there is no indication of what
is going on apart from knowing that you haven't
connected yet. Is that true? When a logon fails,
onLogout is called.
Have you guys thought about adding an app callback
like 'onConnectionFailed' or something like that?
Thanks,
Alex
--- Alex Shterenberg <al...@ya...> wrote:
> 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
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
|