Skip to content

Commit

Permalink
SERVER-3763 SERVER-4643 catch exceptions on connect to other shards w…
Browse files Browse the repository at this point in the history
…hen handling multiple shard case
  • Loading branch information
milkie committed Jan 24, 2012
1 parent 078c791 commit c202889
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions s/client.cpp
Expand Up @@ -223,11 +223,12 @@ namespace mongo {
for ( set<string>::iterator i = shards->begin(); i != shards->end(); i++ ) {
string theShard = *i;
bbb.append( theShard );
ShardConnection conn( theShard , "" );
boost::scoped_ptr<ShardConnection> 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 ){
Expand All @@ -236,15 +237,15 @@ namespace mongo {
// responses.

warning() << "could not get last error from a shard " << theShard << causedBy( e ) << endl;
conn.done();
conn->done();

return false;
}

_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 );
}
Expand All @@ -257,7 +258,7 @@ namespace mongo {
updatedExistingStat = -1;
}

conn.done();
conn->done();
}

bbb.done();
Expand Down

0 comments on commit c202889

Please sign in to comment.