Skip to content

Commit

Permalink
Fix a race condition in TCPDeferAcceptTimeout
Browse files Browse the repository at this point in the history
The test is timing-dependent and it's possible for it to sleep for
longer than the TCP_DEFER_ACCEPT timeout. We currently check if this
happened after sleeping and skip the test if so, but we call `accept`
_after_ this check, so the race still exists. Move the `accept` call to
before the check.

PiperOrigin-RevId: 650240216
  • Loading branch information
peterthejohnston authored and gvisor-bot committed Jul 8, 2024
1 parent 222258a commit db9fab2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions test/syscalls/linux/socket_inet_loopback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1525,13 +1525,13 @@ TEST_P(SocketInetLoopbackTest, TCPDeferAcceptTimeout) {
// timeout is hit.
const auto start = absl::Now();
absl::SleepFor(absl::Seconds(kTCPDeferAccept - 1));
const int result = accept(listen_fd.get(), nullptr, nullptr);
// It's possible that we ended up sleeping for longer than the
// TCP_DEFER_ACCEPT timeout. If this happens, skip this test.
if (absl::Now() >= start + absl::Seconds(kTCPDeferAccept)) {
GTEST_SKIP();
}
ASSERT_THAT(accept(listen_fd.get(), nullptr, nullptr),
SyscallFailsWithErrno(EWOULDBLOCK));
ASSERT_THAT(result, SyscallFailsWithErrno(EWOULDBLOCK));

// Set FD back to blocking.
opts &= ~O_NONBLOCK;
Expand Down

0 comments on commit db9fab2

Please sign in to comment.