summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2010-09-27 14:11:00 -0700
committerAaron <aaron@10gen.com>2010-09-27 14:11:15 -0700
commit14baf5f3c95b0be9057fece5e0380a1627d2f9f6 (patch)
tree224b83462268e69979ed9611ea2f3bbb88dbc9d4
parentbde74e641390db642e6a81d4ca701081eac4f1fd (diff)
downloadmongo-14baf5f3c95b0be9057fece5e0380a1627d2f9f6.tar.gz
better exception handling in mongobridge
-rw-r--r--tools/bridge.cpp67
1 files changed, 39 insertions, 28 deletions
diff --git a/tools/bridge.cpp b/tools/bridge.cpp
index b0e1530d0ac..26c0322bbcb 100644
--- a/tools/bridge.cpp
+++ b/tools/bridge.cpp
@@ -38,37 +38,41 @@ public:
sleepmillis( 500 );
Message m;
while( 1 ) {
- m.reset();
- if ( !mp_.recv( m ) ) {
- cout << "end connection " << mp_.farEnd.toString() << endl;
- mp_.shutdown();
- break;
- }
-
- int oldId = m.header()->id;
- if ( m.operation() == dbQuery || m.operation() == dbMsg || m.operation() == dbGetMore ) {
- bool exhaust = false;
- if ( m.operation() == dbQuery ) {
- DbMessage d( m );
- QueryMessage q( d );
- exhaust = q.queryOptions & QueryOption_Exhaust;
+ try {
+ m.reset();
+ if ( !mp_.recv( m ) ) {
+ cout << "end connection " << mp_.farEnd.toString() << endl;
+ mp_.shutdown();
+ break;
}
- Message response;
- dest.port().call( m, response );
- mp_.reply( m, response, oldId );
- while ( exhaust ) {
- MsgData *header = response.header();
- QueryResult *qr = (QueryResult *) header;
- if ( qr->cursorId ) {
- response.reset();
- dest.port().recv( response );
- mp_.reply( m, response ); // m argument is ignored anyway
- } else {
- exhaust = false;
+
+ int oldId = m.header()->id;
+ if ( m.operation() == dbQuery || m.operation() == dbMsg || m.operation() == dbGetMore ) {
+ bool exhaust = false;
+ if ( m.operation() == dbQuery ) {
+ DbMessage d( m );
+ QueryMessage q( d );
+ exhaust = q.queryOptions & QueryOption_Exhaust;
+ }
+ Message response;
+ dest.port().call( m, response );
+ mp_.reply( m, response, oldId );
+ while ( exhaust ) {
+ MsgData *header = response.header();
+ QueryResult *qr = (QueryResult *) header;
+ if ( qr->cursorId ) {
+ response.reset();
+ dest.port().recv( response );
+ mp_.reply( m, response ); // m argument is ignored anyway
+ } else {
+ exhaust = false;
+ }
}
+ } else {
+ dest.port().say( m, oldId );
}
- } else {
- dest.port().say( m, oldId );
+ } catch ( ... ) {
+ log() << "caught exception in Forwarder, continuing" << endl;
}
}
}
@@ -98,6 +102,12 @@ void cleanup( int sig ) {
::exit( 0 );
}
+void myterminate() {
+ rawOut( "bridge terminate() called, printing stack:" );
+ printStackTrace();
+ abort();
+}
+
void setupSignals() {
signal( SIGINT , cleanup );
signal( SIGTERM , cleanup );
@@ -106,6 +116,7 @@ void setupSignals() {
signal( SIGSEGV , cleanup );
signal( SIGBUS , cleanup );
signal( SIGFPE , cleanup );
+ set_terminate( myterminate );
}
#else
inline void setupSignals() {}