> diff --git a/tools/testing/selftests/bpf/network_helpers.c 
> b/tools/testing/selftests/bpf/network_helpers.c
> index b82f572641b7..2f2719a28f02 100644
> --- a/tools/testing/selftests/bpf/network_helpers.c
> +++ b/tools/testing/selftests/bpf/network_helpers.c

[ ... ]

> @@ -40,6 +41,8 @@
>  #define IPPROTO_MPTCP 262
>  #endif
>
> +#define CONNECTION_IN_PROGRESS_TIMEOUT_MS    3000
> +
>  #define clean_errno() (errno == 0 ? "None" : strerror(errno))
>  #define log_err(MSG, ...) ({                                         \
>                       int __save = errno;                             \

[ ... ]

> @@ -294,7 +297,8 @@ int client_socket(int family, int type,
>  int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t 
> addrlen,
>                   const struct network_helper_opts *opts)
>  {
> -     int fd;
> +     socklen_t errlen;
> +     int fd, err;
>
>       if (!opts)
>               opts = &default_opts;
> @@ -305,13 +309,42 @@ int connect_to_addr(int type, const struct 
> sockaddr_storage *addr, socklen_t add
>               return -1;
>       }
>
> -     if (connect(fd, (const struct sockaddr *)addr, addrlen)) {
> +     err = connect(fd, (const struct sockaddr *)addr, addrlen);
> +     if (err && errno == EINPROGRESS) {
> +             struct pollfd pfd = { .fd = fd, .events = POLLOUT };
> +
> +             err = poll(&pfd, 1, CONNECTION_IN_PROGRESS_TIMEOUT_MS);

Does the fixed 3000 ms timeout override opts->timeout_ms correctly?

client_socket() in this file passes opts->timeout_ms to settimeo(), which
converts it into SO_RCVTIMEO and SO_SNDTIMEO:

tools/testing/selftests/bpf/network_helpers.c:settimeo() {
        ...
        if (timeout_ms > 0) {
                timeout.tv_sec = timeout_ms / 1000;
                timeout.tv_usec = (timeout_ms % 1000) * 1000;
        } else {
                timeout.tv_sec = 3;
                timeout.tv_usec = 0;
        }
        ...
}

tools/testing/selftests/bpf/network_helpers.c:client_socket() {
        ...
        if (settimeo(fd, opts->timeout_ms))
                goto error_close;
        ...
}

That opts->timeout_ms is the caller's requested timeout contract. But the
new poll() discards it and uses CONNECTION_IN_PROGRESS_TIMEOUT_MS instead,
which is always 3000.

This changes observable timing for callers in both directions:

Callers that request a SHORT timeout now wait longer than they asked for.
prog_tests/assign_reuse.c calls connect_to_fd(fd_sv, 100) at lines 42 and
66, requesting a 100 ms budget. A stalled connect now blocks for 100 ms
(SO_SNDTIMEO) plus 3000 ms in poll() - a 30x overrun.
prog_tests/test_tc_tunnel.c sets .timeout_ms = 1000 at line 171.

The commit message explicitly argues against lengthening timeouts:
"increasing the timeout value would increase overall test execution
duration again", yet the patch lengthens these callers' timeouts from
their requested values.

Callers that request a LONG timeout get a shorter window than they asked
for. prog_tests/tc_redirect.c uses TIMEOUT_MILLIS (10000) at lines 428,
561, and 658. prog_tests/xdp_synproxy.c uses 10000 at line 135. On a
loaded runner the connect is now abandoned at SO_SNDTIMEO + 3 s rather
than the requested 10 s.

Would deriving the poll timeout from opts->timeout_ms preserve the single
timeout contract that callers already use?

>
> +             if (err <= 0) {
> +                     if (err == 0) {
> +                             log_err("Connection timeout");
> +                             errno = ETIMEDOUT;
> +                     } else {
> +                             log_err("Failed to poll connection status");
> +                     }
> +                     goto close;
> +             }
> +
> +             errlen = sizeof(err);
> +             if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &errlen) < 0) {
> +                     log_err("Failed to getsockopt");
> +                     goto close;
> +             }
> +
> +             if (err) {
> +                     log_err("Eventually failed to connect to server");
> +                     errno = err;
> +                     goto close;
> +             }
> +     } else if (err) {
>               log_err("Failed to connect to server");
> -             save_errno_close(fd);
> -             return -1;
> +             goto close;
>       }
>
>       return fd;
> +close:
> +     save_errno_close(fd);
> +     return -1;
>  }


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/30795380743

Reply via email to