From e89e736f16fad4166393147b4af07a4efa23c74c Mon Sep 17 00:00:00 2001 From: Bhasker Hariharan Date: Wed, 4 May 2022 11:53:19 -0700 Subject: [PATCH] Deflake TestCloseRead. The test needs to wait for CreateEndpoint to return before cleaning up the stack, otherwise if the netstack is slow to process the final ACK to the handshake the active side of the connection can race ahead to the end and start tearing down the stack. This results in CreateEndpoint failing with a connection aborted error. PiperOrigin-RevId: 446515200 --- pkg/tcpip/adapters/gonet/gonet_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/tcpip/adapters/gonet/gonet_test.go b/pkg/tcpip/adapters/gonet/gonet_test.go index d1529e8696..9f4e593c57 100644 --- a/pkg/tcpip/adapters/gonet/gonet_test.go +++ b/pkg/tcpip/adapters/gonet/gonet_test.go @@ -265,12 +265,14 @@ func TestCloseRead(t *testing.T) { t.Fatalf("AddProtocolAddress(%d, %+v, {}): %s", NICID, protocolAddr, err) } + done := make(chan struct{}) fwd := tcp.NewForwarder(s, 30000, 10, func(r *tcp.ForwarderRequest) { var wq waiter.Queue _, err := r.CreateEndpoint(&wq) if err != nil { t.Fatalf("r.CreateEndpoint() = %v", err) } + close(done) // Endpoint will be closed in deferred s.Close (above). }) @@ -294,6 +296,12 @@ func TestCloseRead(t *testing.T) { if n, err := c.Write([]byte("abc123")); n != 6 || err != nil { t.Errorf("c.Write() = (%d, %v), want (6, nil)", n, err) } + + select { + case <-done: + case <-time.After(1 * time.Second): + t.Fatalf("timed out waiting for r.CreateEndpoint(...) to complete") + } } func TestCloseWrite(t *testing.T) {