diff options
author | Amirsaman Memaripour <amirsaman.memaripour@mongodb.com> | 2022-01-13 19:32:05 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-03-01 16:52:45 +0000 |
commit | 4e292434c65b4e4a23a502b35c8101a4c3cb5c20 (patch) | |
tree | bc7d4d91da465dc4c5de25852f7bed126e5f0233 | |
parent | 85f33bb1a0756c89e0ce8b00599525be381d8e9f (diff) | |
download | mongo-4e292434c65b4e4a23a502b35c8101a4c3cb5c20.tar.gz |
SERVER-62571 Serialize concurrent accesses to `Socket` in `ThrowOnNetworkErrorInEnsureSync`
(cherry picked from commit 1b71c67c9290af3db02d75471eeba894862e1a31)
-rw-r--r-- | src/mongo/transport/transport_layer_asio_test.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/mongo/transport/transport_layer_asio_test.cpp b/src/mongo/transport/transport_layer_asio_test.cpp index d08499e66f9..aec7bb9c934 100644 --- a/src/mongo/transport/transport_layer_asio_test.cpp +++ b/src/mongo/transport/transport_layer_asio_test.cpp @@ -366,7 +366,10 @@ TEST(TransportLayerASIO, ThrowOnNetworkErrorInEnsureSync) { Notification<SessionThread*> mockSessionCreated; tf.sep().setOnStartSession([&](SessionThread& st) { mockSessionCreated.set(&st); }); + unittest::Barrier barrier(2); ConnectionThread connectThread(tf.tla().listenerPort(), [&](ConnectionThread& conn) { + ON_BLOCK_EXIT([&] { barrier.countDownAndWait(); }); + // Linger timeout = 0 causes a RST packet on close. struct linger sl = {1, 0}; if (setsockopt(conn.socket().rawFD(), @@ -379,12 +382,15 @@ TEST(TransportLayerASIO, ThrowOnNetworkErrorInEnsureSync) { } }); - auto& st = *mockSessionCreated.get(); - connectThread.close(); - // We set the timeout to ensure that the setsockopt calls are actually made in ensureSync() + auto& st = *mockSessionCreated.get(); st.session().setTimeout(Milliseconds{500}); + // Synchronize with the connection thread to ensure the connection is closed only after the + // connection thread returns from calling `setsockopt`. + barrier.countDownAndWait(); + connectThread.close(); + // On Mac, setsockopt will immediately throw a SocketException since the socket is closed. // On Linux, we will throw HostUnreachable once we try to actually read the socket. // We allow for either exception here. |