-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
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
bpo-29700: try not to crash when using readline with high FDs. #540
Conversation
We used the input FD for readline with select(), which crashes if it is >1024. Fix it by adding an implementation based on poll(). This does not fix it on all platforms, because poll() does not work correctly on terminals on some platforms. For now, only use the new implemetation on Linux. This also does not fix it on all versions of readline, as some of them use select() internally. Those crash the same way we used to. Fixes issue 29700.
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA. This is necessary for legal reasons before we can look at your contribution. Please follow these steps to help rectify the issue:
Thanks again to your contribution and we look forward to looking at it! |
CLA should be good now (why do the-knights-who-say-ni need me to tell them that? I assumed they'd re-check automatically...). |
/* Issue #26870: poll() does not work with terminals on all OSes. | ||
* Be conservative and use select() on non-Linux. | ||
* TODO(marienz) "glibc" is probably the wrong thing to check, | ||
* but I cannot find an existing "OS is Linux" #define... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe __linux__
? https://sourceforge.net/p/predef/wiki/OperatingSystems/#linux-kernel
It is bad practice to add tests like "OS == Linux". That's similar to browser sniffing, e.g. "This page only works in IE6". Instead, you want to check if the platform supports the specific operation you need. In this case, maybe that would require a configure test that looks if If you do have to test for certain platforms, OSes, etc, it is much better to have a blacklist rather than a whitelist. E.g. if you know The structure of the code is pretty messy as well. This is leading down the path of "ifdef hell". I.e. in a few years, no one will understand the maze of ifdefs and which are actually needed anymore. Maybe have two separate functions, one for platforms that support |
My dilemma with whitelisting vs blacklisting is that poll() is only an advantage if this code gets called with a high FD (which is rare), I can't conveniently test on the one OS I've heard is broken (some versions of OS X), and I've since heard rumours that some other BSDs may also be broken, but I don't know exactly which ones or how. I'm trying to avoid (mostly) unnecessarily regressing OSes I can't test on. Testing at configure time is incorrect if the bug is only present on some versions of the OS (which according to https://bugs.python.org/issue26870#msg265604 it is, only OS X 10.4 and 10.6 are broken), since Python won't necessarily be built on the same OS version it is run on. Is blacklisting OS X 10.4 and 10.6 (and waiting for bug reports if any other OSes are also broken) ok? Agreed the ifdefs are getting messy (there's already a fair number of them, but that's not a good excuse). It'd need some restructuring to support poll and select using separate functions without a lot of duplicated code. I can try to find a way of cleaning that up, once the whitelist vs blacklist thing has been addressed. |
We used the input FD for readline with select(), which crashes if it is >1024.
Fix it by adding an implementation based on poll().
This does not fix it on all platforms, because poll() does not work correctly on
terminals on some platforms. For now, only use the new implemetation on Linux.
This also does not fix it on all versions of readline, as some of them use
select() internally. Those crash the same way we used to.
Fixes issue 29700.