summaryrefslogtreecommitdiff
path: root/src/mongo/s/server.cpp
diff options
context:
space:
mode:
authorHenrik Edin <henrik.edin@mongodb.com>2017-09-05 11:58:12 -0400
committerHenrik Edin <henrik.edin@mongodb.com>2017-09-22 17:13:42 -0400
commit12eb869725f4cefd94f3b4a7e1292f82691ad301 (patch)
tree96a2cab6585001a956b447c3ffc15dd7a1550004 /src/mongo/s/server.cpp
parent6732fbb1fb749e9f22f0ed4633e24515f842dafc (diff)
downloadmongo-12eb869725f4cefd94f3b4a7e1292f82691ad301.tar.gz
SERVER-30471 Service executors take a timeout in shutdown to honor shutdown grace period.
Add shutdown of service entry point, service executors and transport layer for mongos when built with ASAN.
Diffstat (limited to 'src/mongo/s/server.cpp')
-rw-r--r--src/mongo/s/server.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp
index 4af8f9a1d8d..e2e87e187d2 100644
--- a/src/mongo/s/server.cpp
+++ b/src/mongo/s/server.cpp
@@ -177,6 +177,10 @@ ntservice::NtServiceDefaultStrings defaultServiceStrings = {
static ExitCode initService();
#endif
+#if !defined(__has_feature)
+#define __has_feature(x) 0
+#endif
+
// NOTE: This function may be called at any time after
// registerShutdownTask is called below. It must not depend on the
// prior execution of mongo initializers or the existence of threads.
@@ -221,6 +225,37 @@ static void cleanupTask() {
catalog->shutDown(opCtx);
}
+#if __has_feature(address_sanitizer)
+ // When running under address sanitizer, we get false positive leaks due to disorder around
+ // the lifecycle of a connection and request. When we are running under ASAN, we try a lot
+ // harder to dry up the server from active connections before going on to really shut down.
+
+ // Shutdown the TransportLayer so that new connections aren't accepted
+ if (auto tl = serviceContext->getTransportLayer()) {
+ log(LogComponent::kNetwork)
+ << "shutdown: going to close all sockets because ASAN is active...";
+
+ tl->shutdown();
+ }
+
+ // Shutdown the Service Entry Point and its sessions and give it a grace period to complete.
+ if (auto sep = serviceContext->getServiceEntryPoint()) {
+ if (!sep->shutdown(Seconds(10))) {
+ log(LogComponent::kNetwork)
+ << "Service entry point failed to shutdown within timelimit.";
+ }
+ }
+
+ // Shutdown and wait for the service executor to exit
+ if (auto svcExec = serviceContext->getServiceExecutor()) {
+ Status status = svcExec->shutdown(Seconds(5));
+ if (!status.isOK()) {
+ log(LogComponent::kNetwork)
+ << "Service executor failed to shutdown within timelimit: " << status.reason();
+ }
+ }
+#endif
+
// Shutdown Full-Time Data Capture
stopMongoSFTDC();
}