From daceb099cf445390ca18a1ff941af6ffd8c61ba4 Mon Sep 17 00:00:00 2001 From: Eliot Horowitz Date: Wed, 30 Mar 2011 13:49:19 -0400 Subject: [PATCH] safer not master check --- client/dbclient.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/client/dbclient.cpp b/client/dbclient.cpp index 03d1a247eff..7ee63dd5cec 100644 --- a/client/dbclient.cpp +++ b/client/dbclient.cpp @@ -918,13 +918,14 @@ namespace mongo { void DBClientConnection::checkResponse( const char *data, int nReturned ) { /* check for errors. the only one we really care about at - this stage is "not master" */ + * this stage is "not master" + */ + if ( clientSet && nReturned ) { assert(data); BSONObj o(data); - BSONElement e = o.firstElement(); - if ( strcmp(e.fieldName(), "$err") == 0 && - e.type() == String && strncmp(e.valuestr(), "not master", 10) == 0 ) { + BSONElement e = o["$err"]; + if ( e.type() == String && str::contains( e.valuestr() , "not master" ) ) { clientSet->isntMaster(); } }