From d039776e161d0d0bef22db0c709e5c1f61f63fac Mon Sep 17 00:00:00 2001 From: Andrei Vagin Date: Thu, 19 Oct 2023 14:26:07 -0700 Subject: [PATCH] test: fix SetupTimeWaitClose to create a time wait bucket reliably Linux can close a tcp connection without a time wait bucket if fin packets come from both sides close to each other. Let's send some data after the first fin packet to be sure that it is acked before sending fin from another side. PiperOrigin-RevId: 575002422 --- test/util/socket_util.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/util/socket_util.cc b/test/util/socket_util.cc index c148dcf85..d151c557a 100644 --- a/test/util/socket_util.cc +++ b/test/util/socket_util.cc @@ -1113,6 +1113,12 @@ void SetupTimeWaitClose(const TestAddress* listener, ASSERT_THAT(poll(&pfd, 1, kTimeout), SyscallSucceedsWithValue(1)); ASSERT_EQ(pfd.revents, POLLIN); } + // Send/recv some data to be sure that the fin packet has been acked. + char c = 0; + ASSERT_THAT(send(passive_closefd.get(), &c, 1, 0), + SyscallSucceedsWithValue(sizeof(c))); + ASSERT_THAT(recv(active_closefd.get(), &c, 1, 0), + SyscallSucceedsWithValue(sizeof(c))); ASSERT_THAT(shutdown(passive_closefd.get(), SHUT_WR), SyscallSucceeds()); { constexpr int kTimeout = 10000;