Skip to content

CI: fix unstable test \ext\sockets\tests\socket_recvfrom_afpacket_no_port.phpt#22724

Merged
LamentXU123 merged 2 commits into
php:masterfrom
LamentXU123:fix-flacky-CI
Jul 14, 2026
Merged

CI: fix unstable test \ext\sockets\tests\socket_recvfrom_afpacket_no_port.phpt#22724
LamentXU123 merged 2 commits into
php:masterfrom
LamentXU123:fix-flacky-CI

Conversation

@LamentXU123

@LamentXU123 LamentXU123 commented Jul 14, 2026

Copy link
Copy Markdown
Member

Fix flaky CI: https://github.com/php/php-src/actions/runs/29266463698/job/86873055452

When investigating, I've noticed that similar tests does not have this issue. Only socket_recvfrom_afpacket_no_port.phpt is flaky. Which makes me discover a shared logic in tests:

https://github.com/php/php-src/blob/master/ext/sockets/tests/socket_sendto_recvfrom_afpacket_malformed.phpt#L28-L41

<?php
function recv_matching(Socket $s, string $header, int $maxlen = 65536, ?string &$addr = null, &$port = null): string|false {
    socket_set_nonblock($s);
    $deadline = microtime(true) + 5.0;
    while (microtime(true) < $deadline) {
        $bytes = @socket_recvfrom($s, $buf, $maxlen, 0, $addr, $port);
        if ($bytes !== false && is_string($buf) && str_starts_with($buf, $header)) {
            return $buf;
        }
        if ($bytes === false) {
            usleep(1000);
        }
    }
    return false;
}

This allows the test to wait for a frame matching its own Ethernet header before asserting the returned address, so it no longer depends on incidental packet ordering. ETH_P_ALL sockets on loopback can observe unrelated localhost traffic.

And only this single flaky test doesn't have that logic. Let's add them.

@devnexen

Copy link
Copy Markdown
Member

nit: this file is the "no optional port argument" contract test, and the original $bytes >= 60 asserted the return value of the 5-arg call. The new version only checks strlen($buf), dropping that assertion. Equal by construction today, so nothing breaks, but since recv_matching() already has the count, consider surfacing it via a by-ref param to keep the $bytes >= 60 check.

@LamentXU123
LamentXU123 merged commit 0fef3c3 into php:master Jul 14, 2026
18 checks passed
@LamentXU123
LamentXU123 deleted the fix-flacky-CI branch July 14, 2026 18:14
@LamentXU123

Copy link
Copy Markdown
Member Author

Should this be backported to 8.4?

@devnexen

Copy link
Copy Markdown
Member

no. packet filter support did not exist yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants