Skip to content

Commit

Permalink
selftests/bpf: Fix race in tcp_rtt test
Browse files Browse the repository at this point in the history
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 <andriin@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Link: https://lore.kernel.org/bpf/20200314013932.4035712-1-andriin@fb.com
  • Loading branch information
Andrii Nakryiko authored and Daniel Borkmann committed Mar 17, 2020
1 parent 4107890 commit 94c2f50
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tools/testing/selftests/bpf/prog_tests/tcp_rtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ static void *server_thread(void *arg)
return ERR_PTR(err);
}

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

server_done = true;
pthread_join(tid, &server_res);
CHECK_FAIL(pthread_join(tid, &server_res));
CHECK_FAIL(IS_ERR(server_res));

close_server_fd:
Expand Down

0 comments on commit 94c2f50

Please sign in to comment.