Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix "*** buffer overflow detected ***: terminated Aborted" by adding posix poll() io implementation in addition to select() #101

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pmurzakov
Copy link
Contributor

@pmurzakov pmurzakov commented Sep 8, 2022

select() API has a major drawback which doesn't allow to work with fd numbers bigger than 1024. It's a really small number nowadays as the fd table is shared between open files, sockets, connections and so on. While it might be ok for small projects it is critical for high-load projects with a lot of connections open simultaneously or for projects which work with a lot of files dealing with memcache at the same time.

Here's a quote from from first lines of documentation for select():

WARNING: select() can monitor only file descriptors numbers that
are less than FD_SETSIZE (1024)—an unreasonably low limit for
many modern applications—and this limitation will not change.
All modern applications should instead use poll(2) or epoll(7),
which do not suffer this limitation.

https://man7.org/linux/man-pages/man2/select.2.html

Here's a reproduce case:

<?php
for ($i = 0; $i < 1024; $i++) {
        $f[] = fopen("/tmp/testfd_$i", 'a'); // the same effect with files, sockets, open connections, etc
}

$m = memcache_connect('localhost');
if ($m !== false) {
	$a = memcache_get($m, 'key');
}

here's result:

php -f 1.php
*** buffer overflow detected ***: terminated
Aborted (core dumped)

The PR adds option memcache.select_api which is one of poll or select (default). On Win32 only select is supported for now. While it is technically possible to implement it for win32 as it should be available starting from Windows Vista I left it for further scope as I don't have relevant expertise working with Windows APIs.

@pmurzakov pmurzakov marked this pull request as ready for review September 8, 2022 20:03
@pmurzakov pmurzakov closed this Oct 26, 2022
@pmurzakov pmurzakov deleted the NON_BLOCKING_IO_php8 branch October 26, 2022 10:46
@pmurzakov pmurzakov restored the NON_BLOCKING_IO_php8 branch October 26, 2022 10:48
@pmurzakov pmurzakov reopened this Oct 26, 2022
@pmurzakov
Copy link
Contributor Author

Sorry, I closed it by accident

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant