diff options
author | Tyler Seip <Tyler.Seip@mongodb.com> | 2021-12-10 03:45:36 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-03-22 22:09:04 +0000 |
commit | 97705ef5a0283bb5f465f582d9d08259d12e9b23 (patch) | |
tree | 95a2bb700ba0060a2272d9cc9928043f99cb2a47 | |
parent | d365d793d25f08c06f6121fb101464eb971369f9 (diff) | |
download | mongo-97705ef5a0283bb5f465f582d9d08259d12e9b23.tar.gz |
SERVER-61804: Fix race in transport_layer_asio_test
(cherry picked from commit 0455be535f6d8149e86b828d9d75edb185c042e2)
-rw-r--r-- | src/mongo/transport/transport_layer_asio_test.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/mongo/transport/transport_layer_asio_test.cpp b/src/mongo/transport/transport_layer_asio_test.cpp index 7202b4f267f..ea5facf8863 100644 --- a/src/mongo/transport/transport_layer_asio_test.cpp +++ b/src/mongo/transport/transport_layer_asio_test.cpp @@ -527,8 +527,13 @@ TEST(TransportLayerASIO, ConfirmSocketSetOptionOnResetConnections) { asio::io_context ioContext; Acceptor server{ioContext}; Notification<bool> accepted; + Notification<bool> connected; Notification<boost::optional<std::error_code>> caught; server.setOnAccept([&](auto conn) { + // onAccept callbacks can run before the client-side connect() call returns, + // which means there's a race between this socket closing and connect() + // returning. We use the connected flag to prevent the race. + connected.get(); conn->socket.set_option(asio::socket_base::linger(true, 0)); conn->socket.close(); sleepFor(Seconds{1}); @@ -539,6 +544,7 @@ TEST(TransportLayerASIO, ConfirmSocketSetOptionOnResetConnections) { JoinThread client{[&] { asio::ip::tcp::socket client{ioContext}; client.connect(asio::ip::tcp::endpoint(asio::ip::address_v4::loopback(), server.port())); + connected.set(true); accepted.get(); // Just set any option and see what happens. try { |