gorakhargosh / watchdog

Python library and shell utilities to monitor filesystem events.
http://packages.python.org/watchdog/
Apache License 2.0
6.64k stars 698 forks source link

Use of `select.select()` might trigger a `ValueError` if fd>1024 is passed #1079

Closed g-pichler closed 1 month ago

g-pichler commented 1 month ago

I was using watchdog extensively in a quite large application with many threads. It would occasionally result in ValueError: filedescriptor out of range in select() exceptions.

After some searching, I believe that the culprit is indeed the select.select() call. On Linux the man page says

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.

I tried to move to select.poll() in #1078. Maybe there is a better approach than manually checking hasattr(select, 'poll'). Let me know if this works or any other options are preferred. In order to avoid regressions, it might be wise to add a test that opens >1024 file descriptors and then uses watchdog or something along those lines. If this is required, I could take a stab at it.

BoboTiG commented 1 month ago

Any regression test is always very welcome :)

Did those changes completely fixed your issue?

g-pichler commented 1 month ago

So far, yes. I'm running on Linux with Python 3.12. I did not test anything else, except for the tests in the github actions.

I'll try to write a regression test, but it cannot promise anything. It might be annoying to write as the fd is system dependent and maybe hard to reproduce in a unit test.

g-pichler commented 1 month ago

I added a unit test to the pull request. It does fail (on my system) with the current master, but succeeds on #1078.