> diff --git a/tools/testing/selftests/bpf/network_helpers.c
> b/tools/testing/selftests/bpf/network_helpers.c
> index b82f572641b7..97ddbe589e53 100644
> --- a/tools/testing/selftests/bpf/network_helpers.c
> +++ b/tools/testing/selftests/bpf/network_helpers.c
[ ... ]
> @@ -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)) {
> - log_err("Failed to connect to server");
> - save_errno_close(fd);
> - return -1;
> + err = connect(fd, (const struct sockaddr *)addr, addrlen);
> + if (err && errno == EINPROGRESS) {
> + struct pollfd pfd = { .fd = fd, .events = POLLOUT };
> +
> + err = 0;
> + err = poll(&pfd, 1, CONNECTION_IN_PROGRESS_TIMEOUT_MS);
This isn't a bug, but the err = 0; here is immediately overwritten by the
poll() result on the very next line:
err = 0;
err = poll(&pfd, 1, CONNECTION_IN_PROGRESS_TIMEOUT_MS);
Could the err = 0; assignment be dropped?
> +
> + 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("Failed to connect to server");
> + errno = err;
> + goto close;
> + }
> + } else if (err) {
> + 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/29109351717