Close FD on TcpSocketTest loop failure.

This helps prevent the blocking call from getting stuck and causing a test
timeout.

PiperOrigin-RevId: 254325926
This commit is contained in:
Ian Gudger 2019-06-20 20:39:22 -07:00 committed by gVisor bot
parent 3c7448ab6f
commit dc36c34a76
1 changed files with 14 additions and 2 deletions

View File

@ -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;
}