mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Fix a race condition in TCPDeferAcceptTimeout
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
This commit is contained in:
committed by
gVisor bot
parent
222258a585
commit
db9fab290c
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user