Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-87947

Data race on ConnectionThread::_s in ThrowOnNetworkErrorInEnsureSync unittest

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Service Arch
    • ALL
    • Service Arch 2024-04-15, Service Arch 2024-04-29
    • 5

      The test ThrowOnNetworkErrorInEnsureSync creates a 'client/connection thread' as well as a server/listener thread. The client thread connects to the server over localhost (via ::connect using a socket). After the connect call conmpletes, the client thread calls setsockopt on it's socket. The test waits for the server to accept the connection, which it knows it has done by waiting on the mockSessionCreated barrier, before calling close on the client thread's socket.

      However, the barrier merely guarantees that the server/listener has accepted the connection before the test calls close(); it doesn't guarantee that the client has completed it's post-connect hook of running setsockopt. So it's possible that the server/listener creates the mock session for the connection, notifies the main thread via mockSEssionCreated, and the main thread calls ConnectionThread::close (and therefore close on the socket), before the ConnectionThread calls setsockopt. This means the setsockopt could be on an invalid fd.

      We need to add synchronization to ensure that the connection thread has finished running the onConnect hook and therefore will not access the socket before we call close on it (i.e. we need to synchronize reading/writing the socket FD from the main thread vs. ConnectionThread).. This could be accomplished via connectionThread::wait. However, we need to be careful calling close from another thread at all, and should consider if it is even necessary - I don't believe it is.

            Assignee:
            george.wangensteen@mongodb.com George Wangensteen
            Reporter:
            george.wangensteen@mongodb.com George Wangensteen
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: