diff options
-rw-r--r-- | src/mongo/transport/service_entry_point_impl.cpp | 16 | ||||
-rw-r--r-- | src/mongo/transport/service_entry_point_utils.cpp | 6 | ||||
-rw-r--r-- | src/mongo/transport/service_entry_point_utils.h | 2 | ||||
-rw-r--r-- | src/mongo/transport/service_state_machine.h | 4 |
4 files changed, 21 insertions, 7 deletions
diff --git a/src/mongo/transport/service_entry_point_impl.cpp b/src/mongo/transport/service_entry_point_impl.cpp index 5b07f8b2c6c..f4ca1bd4c60 100644 --- a/src/mongo/transport/service_entry_point_impl.cpp +++ b/src/mongo/transport/service_entry_point_impl.cpp @@ -73,7 +73,7 @@ void ServiceEntryPointImpl::startSession(transport::SessionHandle session) { return; } - launchServiceWorkerThread([ this, ssm = std::move(ssm) ]() mutable { + auto workerTask = [this, ssm]() mutable { _nWorkers.addAndFetch(1); const auto guard = MakeGuard([this, &ssm] { _nWorkers.subtractAndFetch(1); }); @@ -96,7 +96,19 @@ void ServiceEntryPointImpl::startSession(transport::SessionHandle session) { if (_nWorkers.load() > numCores) stdx::this_thread::yield(); } - }); + }; + + const auto launchResult = launchServiceWorkerThread(std::move(workerTask)); + if (launchResult.isOK()) { + return; + } + + // We never got off the ground. Manually remove the new SSM from + // the list of sessions and close the associated socket. The SSM + // will be destroyed. + stdx::lock_guard<decltype(_sessionsMutex)> lk(_sessionsMutex); + _sessions.erase(ssmIt); + ssm->terminateIfTagsDontMatch(0); } void ServiceEntryPointImpl::endAllSessions(transport::Session::TagMask tags) { diff --git a/src/mongo/transport/service_entry_point_utils.cpp b/src/mongo/transport/service_entry_point_utils.cpp index 1ce9230d104..16eadb64817 100644 --- a/src/mongo/transport/service_entry_point_utils.cpp +++ b/src/mongo/transport/service_entry_point_utils.cpp @@ -58,7 +58,7 @@ void* runFunc(void* ctx) { } } // namespace -void launchServiceWorkerThread(stdx::function<void()> task) { +Status launchServiceWorkerThread(stdx::function<void()> task) { auto ctx = stdx::make_unique<stdx::function<void()>>(std::move(task)); try { @@ -105,8 +105,10 @@ void launchServiceWorkerThread(stdx::function<void()> task) { #endif // __linux__ } catch (...) { - log() << "failed to create service entry worker thread"; + return {ErrorCodes::InternalError, "failed to create service entry worker thread"}; } + + return Status::OK(); } } // namespace mongo diff --git a/src/mongo/transport/service_entry_point_utils.h b/src/mongo/transport/service_entry_point_utils.h index 79f6dbd0171..83886fbe05b 100644 --- a/src/mongo/transport/service_entry_point_utils.h +++ b/src/mongo/transport/service_entry_point_utils.h @@ -33,6 +33,6 @@ namespace mongo { -void launchServiceWorkerThread(stdx::function<void()> task); +Status launchServiceWorkerThread(stdx::function<void()> task); } // namespace mongo diff --git a/src/mongo/transport/service_state_machine.h b/src/mongo/transport/service_state_machine.h index f5b38d2478a..0e3181f92b9 100644 --- a/src/mongo/transport/service_state_machine.h +++ b/src/mongo/transport/service_state_machine.h @@ -55,8 +55,8 @@ class ServiceStateMachine : public std::enable_shared_from_this<ServiceStateMach ServiceStateMachine& operator=(ServiceStateMachine&) = delete; public: - ServiceStateMachine(ServiceStateMachine&&) = default; - ServiceStateMachine& operator=(ServiceStateMachine&&) = default; + ServiceStateMachine(ServiceStateMachine&&) = delete; + ServiceStateMachine& operator=(ServiceStateMachine&&) = delete; /* * Creates a new ServiceStateMachine for a given session/service context. If sync is true, |