Skip to content

Commit

Permalink
Deflake TestCloseRead.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hbhasker authored and gvisor-bot committed May 4, 2022
1 parent da0c67b commit e89e736
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/tcpip/adapters/gonet/gonet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
})

Expand All @@ -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) {
Expand Down

0 comments on commit e89e736

Please sign in to comment.