summaryrefslogtreecommitdiff
path: root/src/mongo/executor/connection_pool_tl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/executor/connection_pool_tl.cpp')
-rw-r--r--src/mongo/executor/connection_pool_tl.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/mongo/executor/connection_pool_tl.cpp b/src/mongo/executor/connection_pool_tl.cpp
index c27d7604691..f4c7ff1f900 100644
--- a/src/mongo/executor/connection_pool_tl.cpp
+++ b/src/mongo/executor/connection_pool_tl.cpp
@@ -329,6 +329,11 @@ private:
void TLConnection::setup(Milliseconds timeout, SetupCallback cb, std::string instanceName) {
auto anchor = shared_from_this();
+ // Create a shared_ptr to _connMetrics that shares the ownership information with the
+ // anchor. We want to keep this TLConnection instance alive as long as the shared_ptr
+ // to _connMetrics is in use.
+ std::shared_ptr<ConnectionMetrics> connMetricsAnchor{anchor, &_connMetrics};
+
auto pf = makePromiseFuture<void>();
auto handler = std::make_shared<TimeoutHandler>(std::move(pf.promise));
std::move(pf.future).thenRunOn(_reactor).getAsync(
@@ -361,8 +366,13 @@ void TLConnection::setup(Milliseconds timeout, SetupCallback cb, std::string ins
// For transient connections, only use X.509 auth.
auto isMasterHook = std::make_shared<TLConnectionSetupHook>(_onConnectHook, x509AuthOnly);
- AsyncDBClient::connect(
- _peer, _sslMode, _serviceContext, _reactor, timeout, &_connMetrics, _transientSSLContext)
+ AsyncDBClient::connect(_peer,
+ _sslMode,
+ _serviceContext,
+ _reactor,
+ timeout,
+ connMetricsAnchor,
+ _transientSSLContext)
.thenRunOn(_reactor)
.onError([](StatusWith<AsyncDBClient::Handle> swc) -> StatusWith<AsyncDBClient::Handle> {
return Status(ErrorCodes::HostUnreachable, swc.getStatus().reason());