Skip to content

Commit

Permalink
fix MessagingPort leaking SERVER-777
Browse files Browse the repository at this point in the history
From: Guillaume Delannoy <guillaumedelannoy@ymail.com>
Signed-off-by: Eliot Horowitz <eliot@10gen.com>
  • Loading branch information
erh committed Jun 25, 2010
1 parent 8cffdd6 commit 48b6a23
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
24 changes: 12 additions & 12 deletions db/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,22 +193,22 @@ namespace mongo {
LastError *le = new LastError();
lastError.reset(le);

MessagingPort& dbMsgPort = *connGrab;
auto_ptr<MessagingPort> dbMsgPort( connGrab );
connGrab = 0;
Client& c = cc();

try {

c.getAuthenticationInfo()->isLocalHost = dbMsgPort.farEnd.isLocalHost();
c.getAuthenticationInfo()->isLocalHost = dbMsgPort->farEnd.isLocalHost();

Message m;
while ( 1 ) {
m.reset();

if ( !dbMsgPort.recv(m) ) {
if ( !dbMsgPort->recv(m) ) {
if( !cmdLine.quiet )
log() << "end connection " << dbMsgPort.farEnd.toString() << endl;
dbMsgPort.shutdown();
log() << "end connection " << dbMsgPort->farEnd.toString() << endl;
dbMsgPort->shutdown();
break;
}

Expand All @@ -220,11 +220,11 @@ namespace mongo {
lastError.startRequest( m , le );

DbResponse dbresponse;
if ( !assembleResponse( m, dbresponse, dbMsgPort.farEnd.sa ) ) {
out() << curTimeMillis() % 10000 << " end msg " << dbMsgPort.farEnd.toString() << endl;
if ( !assembleResponse( m, dbresponse, dbMsgPort->farEnd.sa ) ) {
out() << curTimeMillis() % 10000 << " end msg " << dbMsgPort->farEnd.toString() << endl;
/* todo: we may not wish to allow this, even on localhost: very low priv accounts could stop us. */
if ( dbMsgPort.farEnd.isLocalHost() ) {
dbMsgPort.shutdown();
if ( dbMsgPort->farEnd.isLocalHost() ) {
dbMsgPort->shutdown();
sleepmillis(50);
problem() << "exiting end msg" << endl;
dbexit(EXIT_CLEAN);
Expand All @@ -235,17 +235,17 @@ namespace mongo {
}

if ( dbresponse.response )
dbMsgPort.reply(m, *dbresponse.response, dbresponse.responseTo);
dbMsgPort->reply(m, *dbresponse.response, dbresponse.responseTo);
}

}
catch ( AssertionException& ) {
problem() << "AssertionException in connThread, closing client connection" << endl;
dbMsgPort.shutdown();
dbMsgPort->shutdown();
}
catch ( SocketException& ) {
problem() << "SocketException in connThread, closing client connection" << endl;
dbMsgPort.shutdown();
dbMsgPort->shutdown();
}
catch ( const ClockSkewException & ) {
exitCleanly( EXIT_CLOCK_SKEW );
Expand Down
5 changes: 2 additions & 3 deletions util/message_server_port.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace mongo {

void threadRun(){
assert( grab );
MessagingPort * p = grab;
auto_ptr<MessagingPort> p( grab );
grab = 0;

Message m;
Expand All @@ -45,12 +45,11 @@ namespace mongo {
break;
}

handler->process( m , p );
handler->process( m , p.get() );
}
}
catch ( ... ){
problem() << "uncaught exception in PortMessageServer::threadRun, closing connection" << endl;
delete p;
}

}
Expand Down

0 comments on commit 48b6a23

Please sign in to comment.