Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add debugging support for multiple destructors, and some guards to pr…

…event this condition from arising
  • Loading branch information...
commit 0131eaf887f0e77941e318ad638273e1260295d2 1 parent 53998ac
@astaple astaple authored
View
21 client/dbclient.cpp
@@ -821,18 +821,19 @@ namespace mongo {
}
DBClientCursor::~DBClientCursor() {
- if ( cursorId && _ownCursor ) {
- BufBuilder b;
- b.append( (int)0 ); // reserved
- b.append( (int)1 ); // number
- b.append( cursorId );
+ DESTRUCTOR_GUARD (
+ if ( cursorId && _ownCursor ) {
+ BufBuilder b;
+ b.append( (int)0 ); // reserved
+ b.append( (int)1 ); // number
+ b.append( cursorId );
- Message m;
- m.setData( dbKillCursors , b.buf() , b.len() );
-
- connector->sayPiggyBack( m );
- }
+ Message m;
+ m.setData( dbKillCursors , b.buf() , b.len() );
+ connector->sayPiggyBack( m );
+ }
+ );
}
/* --- class dbclientpaired --- */
View
10 client/dbclient.h
@@ -500,11 +500,11 @@ namespace mongo {
generate a temporary collection and return its name.
returns a result object which contains:
- { result : <collection_name>,
- numObjects : <number_of_objects_scanned>,
- timeMillis : <job_time>,
- ok : <1_if_ok>,
- [, err : <errmsg_if_error>]
+ { result : <collection_name>,
+ numObjects : <number_of_objects_scanned>,
+ timeMillis : <job_time>,
+ ok : <1_if_ok>,
+ [, err : <errmsg_if_error>]
}
For example one might call:
View
33 db/concurrency.h
@@ -103,7 +103,7 @@ namespace mongo {
_releasedEarly.set(false);
return;
}
- assert(false); // attempt to unlock when wasn't in a write lock
+ massert( 12597, "internal error: attempt to unlock when wasn't in a write lock", false);
}
_state.set(0);
_minfo.leaving();
@@ -220,8 +220,10 @@ namespace mongo {
dbMutex.lock();
}
~writelock() {
- dbunlocking_write();
- dbMutex.unlock();
+ DESTRUCTOR_GUARD(
+ dbunlocking_write();
+ dbMutex.unlock();
+ );
}
};
@@ -230,10 +232,12 @@ namespace mongo {
dbMutex.lock_shared();
}
~readlock() {
- dbunlocking_read();
- dbMutex.unlock_shared();
+ DESTRUCTOR_GUARD(
+ dbunlocking_read();
+ dbMutex.unlock_shared();
+ );
}
- };
+ };
class mongolock {
bool _writelock;
@@ -246,14 +250,15 @@ namespace mongo {
dbMutex.lock_shared();
}
~mongolock() {
- if( _writelock ) {
- dbunlocking_write();
- dbMutex.unlock();
- }
- else {
- dbunlocking_read();
- dbMutex.unlock_shared();
- }
+ DESTRUCTOR_GUARD(
+ if( _writelock ) {
+ dbunlocking_write();
+ dbMutex.unlock();
+ } else {
+ dbunlocking_read();
+ dbMutex.unlock_shared();
+ }
+ );
}
/* this unlocks, does NOT upgrade. that works for our current usage */
void releaseAndWriteLock();
View
10 db/db.cpp
@@ -1068,6 +1068,14 @@ namespace mongo {
exitCleanly();
}
+ // this will be called in certain c++ error cases, for example if there are two active
+ // exceptions
+ void myterminate() {
+ rawOut( "terminate() called, printing stack:\n" );
+ printStackTrace();
+ abort();
+ }
+
void setupSignals() {
assert( signal(SIGSEGV, abruptQuit) != SIG_ERR );
assert( signal(SIGFPE, abruptQuit) != SIG_ERR );
@@ -1083,6 +1091,8 @@ namespace mongo {
sigaddset( &asyncSignals, SIGTERM );
assert( pthread_sigmask( SIG_SETMASK, &asyncSignals, 0 ) == 0 );
boost::thread it( interruptThread );
+
+ set_terminate( myterminate );
}
#else
View
16 jstests/auth/auth1.js
@@ -3,8 +3,8 @@
port = allocatePorts( 1 )[ 0 ];
baseName = "jstests_auth_auth1";
-//m = startMongod( "--auth", "--port", port, "--dbpath", "/data/db/" + baseName, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
-//db = m.getDB( "test" );
+m = startMongod( "--auth", "--port", port, "--dbpath", "/data/db/" + baseName, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
+db = m.getDB( "test" );
t = db[ baseName ];
t.drop();
@@ -61,9 +61,9 @@ assert.eq( 1000, db.eval( function() { return db[ "jstests_auth_auth1" ].count()
assert.eq( 1000, t.group( p ).length );
-//var p = { key : { i : true } ,
-// reduce : function(obj,prev) { db.jstests_auth_auth1.save( {i:10000} ); prev.count++; },
-//initial: { count: 0 }
-//};
-//
-//assert.throws( t.group( p ) );
+var p = { key : { i : true } ,
+ reduce : function(obj,prev) { db.jstests_auth_auth1.save( {i:10000} ); prev.count++; },
+initial: { count: 0 }
+};
+
+assert.throws( function() { t.group( p ) } );
View
9 util/assert_util.h
@@ -188,3 +188,12 @@ namespace mongo {
} catch ( ... ) { \
massert( 10437 , "unknown boost failed" , false ); \
}
+
+#define DESTRUCTOR_GUARD( expression ) \
+ try { \
+ expression; \
+ } catch ( const std::exception &e ) { \
+ problem() << "caught exception (" << e.what() << ") in destructor (" << __FUNCTION__ << ")" << endl; \
+ } catch ( ... ) { \
+ problem() << "caught unknown exception in destructor (" << __FUNCTION__ << ")" << endl; \
+ }
View
2  util/goodies.h
@@ -497,5 +497,5 @@ namespace mongo {
private:
TicketHolder * _holder;
};
-
+
} // namespace mongo
Please sign in to comment.
Something went wrong with that request. Please try again.