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

gh-102494: fix MemoryError when using selectors on Solaris #102495

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The devpoll object now has an upper limit on number of registered file descriptors of 2^18 to prevent memory exhaustion at the time of instantiation.
11 changes: 10 additions & 1 deletion Modules/selectmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ newDevPollObject(PyObject *module)
struct rlimit limit;

/*
** If we try to process more that getrlimit()
** If we try to process more than getrlimit()
** fds, the kernel will give an error, so
** we set the limit here. It is a dynamic
** value, because we can change rlimit() anytime.
Expand All @@ -1106,6 +1106,15 @@ newDevPollObject(PyObject *module)
return NULL;
}

/*
** If the limit is too high (or RLIM_INFINITY), we might allocate huge
** amounts of memory (or even fail to allocate). Because of that, we limit
** the number of allocated structs to 2^18 (which is ~4MB of memory).
*/
if (limit.rlim_cur > (rlim_t)262144) {
limit.rlim_cur = (rlim_t)262144;
}

fd_devpoll = _Py_open("/dev/poll", O_RDWR);
if (fd_devpoll == -1)
return NULL;
Expand Down