From 3c91fa42aeb3adaf86f0987b545be17125f208dc Mon Sep 17 00:00:00 2001 From: Mithun Iyer Date: Thu, 10 Jun 2021 17:20:29 -0700 Subject: Try to avoid accept, incoming ACK race This test checks if an incoming ACK is dropped by the listener when the accept queue is full. The ACK receive handling could race with the test invoking accept on the DUT, causing the test to be flaky. Add a wait time before invoking accept on the DUT to give cycles for the incoming ACK to be handled/dropped by the listener. PiperOrigin-RevId: 378770225 --- test/packetimpact/tests/tcp_listen_backlog_test.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/test/packetimpact/tests/tcp_listen_backlog_test.go b/test/packetimpact/tests/tcp_listen_backlog_test.go index 26c812d0a..fea7d5b6f 100644 --- a/test/packetimpact/tests/tcp_listen_backlog_test.go +++ b/test/packetimpact/tests/tcp_listen_backlog_test.go @@ -55,15 +55,23 @@ func TestTCPListenBacklog(t *testing.T) { // Send the ACK to complete handshake. establishedConn.Send(t, testbench.TCP{Flags: testbench.TCPFlags(header.TCPFlagAck)}) + + // Poll for the established connection ready for accept. dut.PollOne(t, listenFd, unix.POLLIN, time.Second) - // Send the ACK to complete handshake, expect this to be ignored by the - // listener. + // Send the ACK to complete handshake, expect this to be dropped by the + // listener as the accept queue would be full because of the previous + // handshake. incompleteConn.Send(t, testbench.TCP{Flags: testbench.TCPFlags(header.TCPFlagAck)}) + // Let the test wait for sometime so that the ACK is indeed dropped by + // the listener. Without such a wait, the DUT accept can race with + // ACK handling (dropping) causing the test to be flaky. + time.Sleep(100 * time.Millisecond) // Drain the accept queue to enable poll for subsequent connections on the // listener. - dut.Accept(t, listenFd) + fd, _ := dut.Accept(t, listenFd) + dut.Close(t, fd) // The ACK for the incomplete connection should be ignored by the // listening endpoint and the poll on listener should now time out. -- cgit v1.2.3