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
In select.poll.poll() ms can be 0 if timeout < 0 #75967
Comments
According to the documentation select.poll.poll() is blocked for infinite timeout if the timeout argument is negative. But due to rounding it is possible that timeout < 0, but an integer ms passed to the poll() syscall is 0, and poll() is not blocked. |
I suggest to implement ROUND_UP in pytime and use it in all functions Does someone want to work on such patch? The new rounding mode must be test --- select.poll currently uses ROUND_CEILING: round towards +infinity. It looks like you would prefer ROUND_UP: round away from zero, right? In the history of CPython, the rounding mode of functions accepting time, https://haypo.github.io/pytime.html I think that my problem is that I wanted to reuse the same rounding modes |
This particular issue can be fixed by adding the condition (PyFloat_Check(timeout_obj) && PyFloat_AsDouble(timeout_obj) < 0). The problem is only with writing good test for infinity timeout. This test could be also used for testing bpo-31334. |
I have added a Pull Request fixing this issue. The current implementation is checking in the syscall if the value for ms before rounding was negative. To test for this, I call poll.poll in a thread and check that the thread is alive after a join with timeout (so this means it has blocked). Then to clean up, I write to a pipe and therefore it unblocks. The implementation is available in the PR: |
Thank you Pablo. The initial test leaked a thread, now it is much better. Could you please make the test testing different timeout values: None, -1, -1.0, -0.1, -1e-100? |
I have updated both the test and the implementation to address your feedback. |
Ok, so it seems like we need 3 rounding modes:
_PyTime_ROUND_UP and _PyTime_ROUND_CEILING are the same for positive numbers, but using _PyTime_ROUND_CEILING causes this bug: values in ]-0.5; 0.0[ are rounding to zero which gives the wrong behaviour. It seems like _PyTime_ROUND_CEILING is not needed in Python currently. |
Oops, my pending PR 3983 uses _PyTime_ROUND_CEILING :-) Please keep it. |
Thank you for your contribution Pablo. The issue is fixed in 3.6 and 3.7. It is hard to fix it in 2.7. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: