Skip to content

Commit 2cb70db

Browse files
author
greg
committed
Cleanup connection when getlasterror fails
1 parent 7c44081 commit 2cb70db

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

s/client.cpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,21 @@ namespace mongo {
177177
ShardConnection conn( theShard , "" );
178178

179179
BSONObj res;
180-
bool ok = conn->runCommand( "admin" , options , res );
180+
bool ok = false;
181+
try{
182+
ok = conn->runCommand( "admin" , options , res );
183+
}
184+
catch( std::exception &e ){
185+
186+
warning() << "Could not get last error." << m_error_message( e.what() ) << endl;
187+
188+
// Catch everything that happens here, since we need to ensure we return our connection when we're
189+
// finished.
190+
conn.done();
191+
192+
return false;
193+
}
194+
181195
res = res.getOwned();
182196
conn.done();
183197

@@ -228,7 +242,21 @@ namespace mongo {
228242
bbb.append( theShard );
229243
ShardConnection conn( theShard , "" );
230244
BSONObj res;
231-
bool ok = conn->runCommand( "admin" , options , res );
245+
bool ok = false;
246+
try{
247+
ok = conn->runCommand( "admin" , options , res );
248+
}
249+
catch( std::exception &e ){
250+
251+
// Safe to return here, since we haven't started any extra processing yet, just collecting
252+
// responses.
253+
254+
warning() << "Could not get last error." << m_error_message( e.what() ) << endl;
255+
conn.done();
256+
257+
return false;
258+
}
259+
232260
_addWriteBack( writebacks, res );
233261

234262
string temp = DBClientWithCommands::getLastErrorString( res );

0 commit comments

Comments
 (0)