summaryrefslogtreecommitdiffhomepage
path: root/test/syscalls/linux
diff options
context:
space:
mode:
authorBhasker Hariharan <bhaskerh@google.com>2020-09-02 18:19:50 -0700
committergVisor bot <gvisor-bot@google.com>2020-09-02 18:21:47 -0700
commitb69352245ab729cc01088c8258a3167f069bd684 (patch)
tree97a763e5487e66aafd15f6f5726cda727fbe9dda /test/syscalls/linux
parent1fec861939e393f637979e9ee5ef1a253d06c89d (diff)
Fix Accept to not return error for sockets in accept queue.
Accept on gVisor will return an error if a socket in the accept queue was closed before Accept() was called. Linux will return the new fd even if the returned socket is already closed by the peer say due to a RST being sent by the peer. This seems to be intentional in linux more details on the github issue. Fixes #3780 PiperOrigin-RevId: 329828404
Diffstat (limited to 'test/syscalls/linux')
-rw-r--r--test/syscalls/linux/socket_inet_loopback.cc20
1 files changed, 8 insertions, 12 deletions
diff --git a/test/syscalls/linux/socket_inet_loopback.cc b/test/syscalls/linux/socket_inet_loopback.cc
index ffcd90475..54fee2e82 100644
--- a/test/syscalls/linux/socket_inet_loopback.cc
+++ b/test/syscalls/linux/socket_inet_loopback.cc
@@ -1161,30 +1161,26 @@ TEST_P(SocketInetLoopbackTest, TCPAcceptAfterReset) {
SyscallSucceeds());
ASSERT_THAT(close(conn_fd.release()), SyscallSucceeds());
- // TODO(gvisor.dev/issue/3780): Remove this.
if (IsRunningOnGvisor()) {
- // Wait for the RST to be observed.
+ // Gvisor packet procssing is asynchronous and can take a bit of time in
+ // some cases so we give it a bit of time to process the RST packet before
+ // calling accept.
+ //
+ // There is nothing to poll() on so we have no choice but to use a sleep
+ // here.
absl::SleepFor(absl::Milliseconds(100));
}
sockaddr_storage accept_addr;
socklen_t addrlen = sizeof(accept_addr);
- // TODO(gvisor.dev/issue/3780): Remove this.
- if (IsRunningOnGvisor()) {
- ASSERT_THAT(accept(listen_fd.get(),
- reinterpret_cast<sockaddr*>(&accept_addr), &addrlen),
- SyscallFailsWithErrno(ENOTCONN));
- return;
- }
-
- conn_fd = ASSERT_NO_ERRNO_AND_VALUE(Accept(
+ auto accept_fd = ASSERT_NO_ERRNO_AND_VALUE(Accept(
listen_fd.get(), reinterpret_cast<sockaddr*>(&accept_addr), &addrlen));
ASSERT_EQ(addrlen, listener.addr_len);
int err;
socklen_t optlen = sizeof(err);
- ASSERT_THAT(getsockopt(conn_fd.get(), SOL_SOCKET, SO_ERROR, &err, &optlen),
+ ASSERT_THAT(getsockopt(accept_fd.get(), SOL_SOCKET, SO_ERROR, &err, &optlen),
SyscallSucceeds());
ASSERT_EQ(err, ECONNRESET);
ASSERT_EQ(optlen, sizeof(err));