mirror of
https://github.com/hanzoai/visor.git
synced 2026-09-24 17:04:14 +00:00
Fix TSan data race in UDP Socket Tests
TSan flags concurrent socket operations on the identical host FD as a data race. This commit uses dup() to duplicate the socket file descriptor specifically for the background thread's connect() call, so sendto and connect can execute concurrently from two different threads without TSan data race on the fd struct. PiperOrigin-RevId: 955479183
This commit is contained in:
@@ -430,8 +430,16 @@ TEST_P(UdpSocketTest, ConnectSimultaneousWriteToInvalidPort) {
|
||||
ASSERT_THAT(close(s.release()), SyscallSucceeds());
|
||||
|
||||
// Now connect to the port that we just released.
|
||||
ScopedThread t([&] {
|
||||
ASSERT_THAT(connect(sock_.get(), addr, addrlen_), SyscallSucceeds());
|
||||
//
|
||||
// Duplicate the socket file descriptor to prevent a TSan data race.
|
||||
// TSan flags concurrent socket operations on the identical host FD
|
||||
// (from the concurrent sendto() in the main thread) as a data race,
|
||||
// so use a separate FD pointing to the same underlying socket.
|
||||
int dup_fd = dup(sock_.get());
|
||||
ASSERT_GE(dup_fd, 0);
|
||||
ScopedThread t([&, dup_fd] {
|
||||
ASSERT_THAT(connect(dup_fd, addr, addrlen_), SyscallSucceeds());
|
||||
close(dup_fd);
|
||||
});
|
||||
|
||||
char buf[512] = {};
|
||||
|
||||
Reference in New Issue
Block a user