Skip to content

Commit 8744bf3

Browse files
tomerdbzgalnoam
authored andcommitted
issue: 4680622 Fix sporadic udp_connect fails
The mapped_ipv4_connect test was failing sporadically with recv() returning -1 and errno=EINTR (Interrupted system call). This occurred due to a race condition between the child process exit and the parent's blocking recv() call. The test forks a child process to send a UDP packet, while the parent waits to receive it. When the child completes and exits, the kernel delivers a SIGCHLD signal to the parent. If this signal arrives while the parent is blocked in recv(), the system call is interrupted and returns EINTR. The timing of SIGCHLD delivery relative to recv() determines whether the test passes or fails: - SIGCHLD before recv(): packet received successfully - SIGCHLD during recv(): recv() interrupted with EINTR This is a classic Unix signal handling issue. The standard solution is to retry the system call when interrupted by a signal. Wrap recv() in a do-while loop that retries on EINTR, following the standard Unix pattern for handling interrupted system calls. This ensures the test completes successfully regardless of signal timing. Signed-off-by: Tomer Cabouly <[email protected]>
1 parent f7e0448 commit 8744bf3

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

tests/gtest/udp/udp_connect.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,9 @@ TEST_F(udp_connect, mapped_ipv4_connect)
223223
barrier_fork(pid);
224224

225225
char buffer[8] = {0};
226-
rc = recv(fd, buffer, sizeof(buffer), 0);
226+
do {
227+
rc = recv(fd, buffer, sizeof(buffer), 0);
228+
} while (rc < 0 && errno == EINTR);
227229
EXPECT_EQ_ERRNO(8, rc);
228230
}
229231

0 commit comments

Comments
 (0)