diff --git a/src/mongo/s/client.cpp b/src/mongo/s/client.cpp index 91b2e1a178c51..5aae8df9d8967 100644 --- a/src/mongo/s/client.cpp +++ b/src/mongo/s/client.cpp @@ -230,11 +230,12 @@ namespace mongo { for ( set::iterator i = shards->begin(); i != shards->end(); i++ ) { string theShard = *i; bbb.append( theShard ); - ShardConnection conn( theShard , "" ); + boost::scoped_ptr conn; BSONObj res; bool ok = false; try { - ok = conn->runCommand( "admin" , options , res ); + conn.reset( new ShardConnection( theShard , "" ) ); // constructor can throw if shard is down + ok = (*conn)->runCommand( "admin" , options , res ); shardRawGLE.append( theShard , res ); } catch( std::exception &e ){ @@ -243,7 +244,7 @@ namespace mongo { // responses. warning() << "could not get last error from a shard " << theShard << causedBy( e ) << endl; - conn.done(); + conn->done(); return false; } @@ -251,7 +252,7 @@ namespace mongo { _addWriteBack( writebacks, res ); string temp = DBClientWithCommands::getLastErrorString( res ); - if ( conn->type() != ConnectionString::SYNC && ( ok == false || temp.size() ) ) { + if ( (*conn)->type() != ConnectionString::SYNC && ( ok == false || temp.size() ) ) { errors.push_back( temp ); errorObjects.push_back( res ); } @@ -264,7 +265,7 @@ namespace mongo { updatedExistingStat = -1; } - conn.done(); + conn->done(); } bbb.done();