Skip to content

Commit 94c2f50

Browse files
anakryikoborkmann
authored andcommitted
selftests/bpf: Fix race in tcp_rtt test
Previous attempt to make tcp_rtt more robust introduced a new race, in which server_done might be set to true before server can actually accept any connection. Fix this by unconditionally waiting for accept(). Given socket is non-blocking, if there are any problems with client side, it should eventually close listening FD and let server thread exit with failure. Fixes: 4cd729f ("selftests/bpf: Make tcp_rtt test more robust to failures") Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Martin KaFai Lau <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 4107890 commit 94c2f50

File tree

1 file changed

+2
-2
lines changed
  • tools/testing/selftests/bpf/prog_tests

1 file changed

+2
-2
lines changed

tools/testing/selftests/bpf/prog_tests/tcp_rtt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ static void *server_thread(void *arg)
226226
return ERR_PTR(err);
227227
}
228228

229-
while (!server_done) {
229+
while (true) {
230230
client_fd = accept(fd, (struct sockaddr *)&addr, &len);
231231
if (client_fd == -1 && errno == EAGAIN) {
232232
usleep(50);
@@ -272,7 +272,7 @@ void test_tcp_rtt(void)
272272
CHECK_FAIL(run_test(cgroup_fd, server_fd));
273273

274274
server_done = true;
275-
pthread_join(tid, &server_res);
275+
CHECK_FAIL(pthread_join(tid, &server_res));
276276
CHECK_FAIL(IS_ERR(server_res));
277277

278278
close_server_fd:

0 commit comments

Comments
 (0)