Operational Defect Database

BugZero found this defect 67 days ago.

MongoDB | 2608008

Data race on ConnectionThread::_s in ThrowOnNetworkErrorInEnsureSync unittest

Last update date:

3/14/2024

Affected products:

MongoDB Server

Affected releases:

No affected releases provided.

Fixed releases:

No fixed releases provided.

Description:

Info

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.

Top User Comments


Steps to Reproduce


Additional Resources / Links

Share:

BugZero® Risk Score

What's this?

Coming soon

Status

Needs Scheduling

Learn More

Search:

...