summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorIan Gudger <igudger@google.com>2019-06-20 20:39:22 -0700
committergVisor bot <gvisor-bot@google.com>2019-06-20 20:40:31 -0700
commitdc36c34a766500507e4ac90547b58b88625bbc0d (patch)
treed0188f345b6c2a2d2f4f01385e5d867f1e763a08
parent3c7448ab6f178cfc171545d15ae039f318e38225 (diff)
Close FD on TcpSocketTest loop failure.
This helps prevent the blocking call from getting stuck and causing a test timeout. PiperOrigin-RevId: 254325926
-rw-r--r--test/syscalls/linux/tcp_socket.cc16
1 files changed, 14 insertions, 2 deletions
diff --git a/test/syscalls/linux/tcp_socket.cc b/test/syscalls/linux/tcp_socket.cc
index 5efeb96c8..4597e91e3 100644
--- a/test/syscalls/linux/tcp_socket.cc
+++ b/test/syscalls/linux/tcp_socket.cc
@@ -265,10 +265,16 @@ TEST_P(TcpSocketTest, BlockingLargeWrite_NoRandomSave) {
ScopedThread t([this, &read_bytes]() {
// Avoid interrupting the blocking write in main thread.
const DisableSave ds;
+
+ // Take ownership of the FD so that we close it on failure. This will
+ // unblock the blocking write below.
+ FileDescriptor fd(t_);
+ t_ = -1;
+
char readbuf[2500] = {};
int n = -1;
while (n != 0) {
- ASSERT_THAT(n = RetryEINTR(read)(t_, &readbuf, sizeof(readbuf)),
+ ASSERT_THAT(n = RetryEINTR(read)(fd.get(), &readbuf, sizeof(readbuf)),
SyscallSucceeds());
read_bytes += n;
}
@@ -342,10 +348,16 @@ TEST_P(TcpSocketTest, BlockingLargeSend_NoRandomSave) {
ScopedThread t([this, &read_bytes]() {
// Avoid interrupting the blocking write in main thread.
const DisableSave ds;
+
+ // Take ownership of the FD so that we close it on failure. This will
+ // unblock the blocking write below.
+ FileDescriptor fd(t_);
+ t_ = -1;
+
char readbuf[2500] = {};
int n = -1;
while (n != 0) {
- ASSERT_THAT(n = RetryEINTR(read)(t_, &readbuf, sizeof(readbuf)),
+ ASSERT_THAT(n = RetryEINTR(read)(fd.get(), &readbuf, sizeof(readbuf)),
SyscallSucceeds());
read_bytes += n;
}