mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Connect before closing the destination socket to acquire different port
In the ConnectWriteToInvalidPort test case, the target socket is closed before the source socket sends data to generate and then verify reception of an ICMP error packet. If the target socket is closed before an outgoing port number is picked for the source socket, the source socket might be assigned the same port number for sending as its destination. The result is that the source socket receives the packet it sends and so no error is generated. This results in test flakiness, though with very low probability. Fixes #8338 PiperOrigin-RevId: 499244574
This commit is contained in:
@@ -385,11 +385,14 @@ TEST_P(UdpSocketTest, ConnectWriteToInvalidPort) {
|
||||
ASSERT_THAT(getsockname(s.get(), addr, &addrlen), SyscallSucceeds());
|
||||
EXPECT_EQ(addrlen, addrlen_);
|
||||
EXPECT_NE(*Port(&addr_storage), 0);
|
||||
ASSERT_THAT(close(s.release()), SyscallSucceeds());
|
||||
|
||||
// Now connect to the port that we just released. This should generate an
|
||||
// ECONNREFUSED error.
|
||||
// Connect to the same address. This won't send data yet but will ensure that
|
||||
// the local port chosen for the connecting socket is different from the
|
||||
// remote port, since it is still in use.
|
||||
ASSERT_THAT(connect(sock_.get(), addr, addrlen_), SyscallSucceeds());
|
||||
|
||||
// Now free the destination port and then send a packet to it. This should
|
||||
// generate an ECONNREFUSED error.
|
||||
ASSERT_THAT(close(s.release()), SyscallSucceeds());
|
||||
char buf[512];
|
||||
RandomizeBuffer(buf, sizeof(buf));
|
||||
// Send from sock_ to an unbound port.
|
||||
|
||||
Reference in New Issue
Block a user