Skip to content

Commit 52a7871

Browse files
patrickfreedMongoDB Bot
authored andcommitted
SERVER-86694 Fix crash when AsioTransportLayer is shut down between setup and start (#19073) (#19114)
GitOrigin-RevId: 5eff1aa2d23b15324f92a8f596175ae17c56a409
1 parent 2063be6 commit 52a7871

File tree

8 files changed

+19
-37
lines changed

8 files changed

+19
-37
lines changed

src/mongo/transport/asio/asio_transport_layer.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,18 +1215,17 @@ Status AsioTransportLayer::start() {
12151215
return ShutdownStatus;
12161216
}
12171217

1218-
if (_sessionManager) {
1219-
uassertStatusOK(_sessionManager->start());
1220-
}
1221-
1222-
if (_listenerOptions.isIngress() && _listener.state == Listener::State::kNew) {
1223-
invariant(_sessionManager);
1224-
_listener.thread = stdx::thread([this] { _runListener(); });
1225-
_listener.cv.wait(lk, [&] { return _listener.state != Listener::State::kNew; });
1226-
return Status::OK();
1218+
if (_listenerOptions.isIngress()) {
1219+
// Only start the listener thread if the TL wasn't shut down before start() was invoked.
1220+
if (_listener.state == Listener::State::kNew) {
1221+
invariant(_sessionManager);
1222+
_listener.thread = stdx::thread([this] { _runListener(); });
1223+
_listener.cv.wait(lk, [&] { return _listener.state != Listener::State::kNew; });
1224+
}
1225+
} else {
1226+
invariant(_acceptorRecords.empty());
12271227
}
12281228

1229-
invariant(_acceptorRecords.empty());
12301229
return Status::OK();
12311230
}
12321231

src/mongo/transport/asio/asio_transport_layer_test.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,16 @@ TEST(AsioTransportLayer, TCPResetAfterConnectionIsSilentlySwallowed) {
342342
ASSERT_EQ(sessionsCreated.load(), 0);
343343
}
344344

345+
TEST(AsioTransportLayer, StopAcceptingSessionsBeforeStart) {
346+
auto sm = std::make_unique<test::MockSessionManager>();
347+
auto tla = std::make_unique<AsioTransportLayer>(defaultTLAOptions(), std::move(sm));
348+
ON_BLOCK_EXIT([&] { tla->shutdown(); });
349+
350+
ASSERT_OK(tla->setup());
351+
tla->stopAcceptingSessions();
352+
ASSERT_OK(tla->start());
353+
}
354+
345355
#ifdef __linux__
346356
/**
347357
* Test that the server successfully captures the TCP socket queue depth, and places the value both
@@ -969,10 +979,6 @@ class AsioNetworkingBatonTest : public ServiceContextTest {
969979
_join();
970980
}
971981

972-
Status start() override {
973-
return Status::OK();
974-
}
975-
976982
void startSession(std::shared_ptr<Session> session) override {
977983
stdx::lock_guard lk{_mutex};
978984
_sessions.push_back(session);

src/mongo/transport/grpc/grpc_transport_layer_impl.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,6 @@ Status GRPCTransportLayerImpl::start() {
192192
"tlsFIPSMode is not supported when gRPC mode is enabled",
193193
!sslGlobalParams.sslFIPSMode);
194194

195-
if (_sessionManager) {
196-
uassertStatusOK(_sessionManager->start());
197-
}
198-
199195
if (_server) {
200196
invariant(_sessionManager);
201197
_server->start();

src/mongo/transport/session_manager.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,6 @@ class SessionManager {
7777
*/
7878
virtual void endAllSessions(Client::TagMask tags) = 0;
7979

80-
/**
81-
* Starts the session manager.
82-
*/
83-
virtual Status start() = 0;
84-
8580
/**
8681
* Shuts down the session manager.
8782
*/

src/mongo/transport/session_manager_common.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ class SessionManagerCommon : public SessionManager {
6060
void endSessionByClient(Client* client) override;
6161
void endAllSessionsNoTagMask();
6262

63-
Status start() override {
64-
return Status::OK();
65-
}
6663
bool shutdown(Milliseconds timeout) override;
6764
bool shutdownAndWait(Milliseconds timeout);
6865
bool waitForNoSessions(Milliseconds timeout);

src/mongo/transport/session_manager_noop.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ class SessionManagerNoop : public SessionManager {
4141
void startSession(std::shared_ptr<transport::Session> session) override {}
4242
void endAllSessions(Client::TagMask tags) override {}
4343
void endSessionByClient(Client* client) override {}
44-
Status start() override {
45-
return Status::OK();
46-
}
4744
bool shutdown(Milliseconds timeout) override {
4845
return true;
4946
}

src/mongo/transport/test_fixtures.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,6 @@ class MockSessionManager : public SessionManager {
183183
_join();
184184
}
185185

186-
Status start() override {
187-
return Status::OK();
188-
}
189-
190186
void startSession(std::shared_ptr<transport::Session> session) override {
191187
LOGV2(6109510, "Accepted connection", "remote"_attr = session->remote());
192188
auto& newSession = [&]() -> SessionThread& {

src/mongo/util/net/ssl_manager_test.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,6 @@ class SessionManagerUtil : public transport::SessionManager {
7777
old_sessions.clear();
7878
}
7979

80-
Status start() override {
81-
return Status::OK();
82-
}
83-
8480
bool shutdown(Milliseconds timeout) override {
8581
return true;
8682
}

0 commit comments

Comments
 (0)