From a08ec09cc8f9856e79a8cadf53d11387f0e2408a Mon Sep 17 00:00:00 2001 From: Alex Konradi Date: Tue, 28 Mar 2023 20:33:56 -0700 Subject: [PATCH] Use non-zero timeout for polling TCP connection Allow poll to wait for a signal on the socket instead of requiring that it be set immediately. This fixes flakiness caused by connections not being established fast enough. For https://fxbug.dev/124433 PiperOrigin-RevId: 520212110 --- test/util/socket_util.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/util/socket_util.cc b/test/util/socket_util.cc index 4d3ed5f78..c07309def 100644 --- a/test/util/socket_util.cc +++ b/test/util/socket_util.cc @@ -354,7 +354,12 @@ CreateTCPConnectAcceptSocketPair(int bound, FileDescriptor connected, int type, if (connect_result == -1) { struct pollfd connect_poll = {connected.get(), POLLOUT | POLLERR | POLLHUP, 0}; - RETURN_ERROR_IF_SYSCALL_FAIL(RetryEINTR(poll)(&connect_poll, 1, 0)); + int num_fds; + RETURN_ERROR_IF_SYSCALL_FAIL( + (num_fds = RetryEINTR(poll)(&connect_poll, 1, -1))); + if (num_fds != 1) { + return PosixError(ENOTCONN, "connect failed"); + } int error = 0; socklen_t errorlen = sizeof(error); RETURN_ERROR_IF_SYSCALL_FAIL(