Skip to content

Fall back to epoll_wait when epoll_pwait2 is unavailable at runtime - #23825

Open
bukka wants to merge 1 commit into
php:masterfrom
bukka:poll_epoll_pwait2_fallback
Open

bukka wants to merge 1 commit into
php:masterfrom
bukka:poll_epoll_pwait2_fallback

Conversation

@bukka

@bukka bukka commented Sep 21, 2026

Copy link
Copy Markdown
Member

HAVE_EPOLL_PWAIT2 only means the libc exports the wrapper, which glibc does since 2.35 regardless of the running kernel. A PHP built on a kernel with epoll_pwait2 and run on one older than 5.11 gets ENOSYS from every Context::wait(), which makes the epoll backend and thus Backend::Auto unusable. This is the normal shape for Docker images, distro packages and static builds, and it also happens under emulation layers that lack the syscall, as seen in #23478.

Try epoll_pwait2 first and on ENOSYS or ENOTSUP switch the process to epoll_wait, retrying the current call so the caller never sees the error. The flag is process-wide and atomic so ZTS builds do not race on it.

The configure check is unchanged, so the plain link check keeps working when cross-compiling.

Alternative to #23478.

HAVE_EPOLL_PWAIT2 only tells whether the libc exports the wrapper, which
glibc does since 2.35 regardless of the running kernel. A PHP built on a
kernel with epoll_pwait2 and run on one older than 5.11 gets ENOSYS from
every Context::wait() call, which makes the epoll backend and thus the
Auto backend unusable. The same happens under emulation layers that do
not implement the syscall.

Try epoll_pwait2 first and on ENOSYS or ENOTSUP switch the process to
epoll_wait with a millisecond timeout, retrying the current call so the
failure is never visible to the caller. The flag is process wide since
kernel support is the same for every thread, and it is atomic so the
first concurrent waits in a ZTS build do not race on it.
nfds = epoll_wait(backend_data->epoll_fd, backend_data->events, max_events, timeout_ms);
}

if (nfds > 0) {

@devnexen devnexen Sep 21, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I get 'ndfs' may be unitialized [-Wmaybe-uninitialized].

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