Skip to content

Commit

Permalink
tests: Deflake socket_inet_loopback_isolated_test
Browse files Browse the repository at this point in the history
This test case creates one connection, then it closes one end of it. After that
it waits for a linger timeout and tries to create the second connection with
the same client source port. The test is flaky if the second half of the fist
connection isn't closed before creating the second connection.

PiperOrigin-RevId: 715924851
  • Loading branch information
avagin authored and gvisor-bot committed Jan 15, 2025
1 parent 1864d9d commit ca3c23d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion runsc/boot/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,11 @@ func (n *Network) CreateLinksAndRoutes(args *CreateLinksAndRoutesArgs, _ *struct
nicID := n.Stack.NextNICID()
nicids[link.Name] = nicID

linkEP := ethernet.New(loopback.New())
var linkEP stack.LinkEndpoint
linkEP = ethernet.New(loopback.New())
if args.LogPackets {
linkEP = sniffer.New(linkEP)
}

log.Infof("Enabling loopback interface %q with id %d on addresses %+v", link.Name, nicID, link.Addresses)
opts := stack.NICOptions{
Expand Down
7 changes: 7 additions & 0 deletions test/syscalls/linux/socket_inet_loopback_isolated.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@ TEST_P(SocketInetLoopbackIsolatedTest, TCPFinWait2Test) {
ASSERT_THAT(bind(conn_fd2.get(), AsSockAddr(&conn_bound_addr), conn_addrlen),
SyscallSucceeds());

// Close the `accepted` end otherwise connect can return ECONNREFUSED.
constexpr int kTCPLingerTimeout0 = 0;
EXPECT_THAT(setsockopt(accepted.get(), IPPROTO_TCP, TCP_LINGER2,
&kTCPLingerTimeout0, sizeof(kTCPLingerTimeout0)),
SyscallSucceedsWithValue(0));
shutdown(accepted.get(), SHUT_WR);

ASSERT_THAT(
RetryEINTR(connect)(conn_fd2.get(), AsSockAddr(&conn_addr), conn_addrlen),
SyscallSucceeds());
Expand Down

0 comments on commit ca3c23d

Please sign in to comment.