Skip to content

Commit 4ce6192

Browse files
committed
CXX-334 fix shutdown in tests that manually call ReplicaSetMonitor::shutdown()
1 parent 7f5791a commit 4ce6192

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/mongo/client/init.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "mongo/platform/atomic_word.h"
2626
#include "mongo/stdx/functional.h"
2727
#include "mongo/util/background.h"
28+
#include "mongo/util/log.h"
2829
#include "mongo/util/net/sock.h"
2930

3031
namespace mongo {
@@ -115,7 +116,12 @@ namespace client {
115116

116117
Status result = ReplicaSetMonitor::shutdown(Options::current().autoShutdownGracePeriodMillis());
117118
if (!result.isOK()) {
118-
return result;
119+
if (result == ErrorCodes::ExceededTimeLimit) {
120+
return result;
121+
}
122+
warning() << "The ReplicaSetMonitor was shutdown prior to driver termination. "
123+
<< "This is a non-fatal error that can occur if you are calling "
124+
<< "ReplicaSetMonitor::shutdown() manually." << std::endl;
119125
}
120126
shutdownNetworking();
121127
return Status::OK();

src/mongo/client/replica_set_monitor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ namespace {
441441
Status ReplicaSetMonitor::initialize() {
442442
boost::lock_guard<boost::mutex> lock(watcherLifetimeLock);
443443
if (replicaSetMonitorWatcher) {
444-
return Status(ErrorCodes::IllegalOperation,
444+
return Status(ErrorCodes::AlreadyInitialized,
445445
"ReplicaSetMonitorWatcher has already been initialized");
446446
}
447447
replicaSetMonitorWatcher.reset(new ReplicaSetMonitorWatcher());
@@ -451,15 +451,15 @@ namespace {
451451
Status ReplicaSetMonitor::shutdown(int gracePeriodMillis) {
452452
boost::lock_guard<boost::mutex> lock(watcherLifetimeLock);
453453
if (!replicaSetMonitorWatcher) {
454-
return Status(ErrorCodes::IllegalOperation,
454+
return Status(ErrorCodes::InternalError,
455455
"ReplicaSetMonitorWatcher has not been initialized");
456456
}
457457
// Call cancel first, in case the RSMW was never started.
458458
replicaSetMonitorWatcher->cancel();
459459
replicaSetMonitorWatcher->stop();
460460
bool success = replicaSetMonitorWatcher->wait(gracePeriodMillis);
461461
if (!success) {
462-
return Status(ErrorCodes::InternalError,
462+
return Status(ErrorCodes::ExceededTimeLimit,
463463
"Timed out waiting for ReplicaSetMonitorWatcher to shutdown");
464464
}
465465
replicaSetMonitorWatcher.reset();

0 commit comments

Comments
 (0)