summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTad Marshall <tad@10gen.com>2013-08-02 08:00:12 -0400
committerTad Marshall <tad@10gen.com>2013-08-02 10:03:22 -0400
commit1de7cd5518e2743a5e9e1db7727dccc488be43da (patch)
treedcd33a8898b006a3b90bdfae1b7bfc61b7ae110c
parentd0f73fae4db80f586c06f390f4c1ac1ecc4d952d (diff)
downloadmongo-1de7cd5518e2743a5e9e1db7727dccc488be43da.tar.gz
SERVER-8707 Stop the ReplicaSetMonitorWatcher loop on process termination
Use StaticObserver to end ReplicaSetMonitorWatcher's loop when a program using the C++ driver exits. Move the sleep to the bottom of the loop to reduce the window between checking for termination and the call to ReplicaSetMonitor::checkAll().
-rw-r--r--src/mongo/client/dbclient_rs.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/mongo/client/dbclient_rs.cpp b/src/mongo/client/dbclient_rs.cpp
index c53e4fca5da..50d00b65103 100644
--- a/src/mongo/client/dbclient_rs.cpp
+++ b/src/mongo/client/dbclient_rs.cpp
@@ -31,6 +31,7 @@
#include "mongo/db/jsobj.h"
#include "mongo/db/json.h"
#include "mongo/util/background.h"
+#include "mongo/util/concurrency/mutex.h" // for StaticObserver
#include "mongo/util/scopeguard.h"
#include "mongo/util/timer.h"
@@ -49,6 +50,7 @@ namespace mongo {
* _seedServers -- list (map) of servers
* _sets -- list (map) of ReplicaSetMonitors
* replicaSetMonitorWatcher -- background job to check Replica Set members
+ * staticObserver -- sentinel to detect process termination
*
* Related to:
* SERVER-8891 -- Simple client fail with segmentation fault in mongoclient library
@@ -80,8 +82,7 @@ namespace mongo {
protected:
void run() {
log() << "starting" << endl;
- while ( ! inShutdown() ) {
- sleepsecs( 10 );
+ while ( !inShutdown() && !StaticObserver::_destroyingStatics ) {
try {
ReplicaSetMonitor::checkAll( true );
}
@@ -91,6 +92,7 @@ namespace mongo {
catch ( ... ) {
error() << "unknown error" << endl;
}
+ sleepsecs( 10 );
}
}
@@ -99,6 +101,8 @@ namespace mongo {
} replicaSetMonitorWatcher;
+ static StaticObserver staticObserver;
+
/*
* Set of commands that can be used with $readPreference