Skip to content

ext/standard: Fix Io\Poll timeouts longer than INT_MAX milliseconds - #23793

Merged
bukka merged 1 commit into
php:masterfrom
nicolas-grekas:io-poll-timeout-overflow
Sep 21, 2026
Merged

bukka merged 1 commit into
php:masterfrom
nicolas-grekas:io-poll-timeout-overflow

Conversation

@nicolas-grekas

Copy link
Copy Markdown
Contributor

Also found while building an Io\Poll driver for revolt/event-loop, unrelated to #23791.

php_poll_timespec_to_ms() casts tv_sec * 1000 to an int, so a timeout of more than about 24 days wraps around and wait() returns almost at once:

$ctx = new Io\Poll\Context(Io\Poll\Backend::Poll);
$ctx->add(new StreamPollHandle($socket), [Io\Poll\Event::Read]);
$ctx->wait(Time\Duration::fromSeconds(158913790)); // five years, returns empty after 50ms

The value is capped at INT_MAX now. This hits the poll and WSAPoll backends, and epoll only where it falls back to epoll_wait(), since epoll_pwait2() takes the timespec as is.

A timeout beyond 24 days still ends early, without any event, which is what the other users of that helper already assume. Waiting the whole duration would mean looping in each backend, tell me if you would rather have that.

php_poll_timespec_to_ms() cast seconds * 1000 to an int, so a wait() of more than
about 24 days wrapped around: five years came out as 48ms on the poll backend.
The value is capped now. epoll is only affected where it falls back to
epoll_wait(), since epoll_pwait2() takes the timespec as is.
@bukka
bukka merged commit 39f98f7 into php:master Sep 21, 2026
18 checks passed
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