-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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-126876: Fix socket internal_select() for large timeout #126968
Conversation
If the timeout is larger than INT_MAX, replace it with INT_MAX, in the poll() code path. Add an unit test.
cc @sobolevn |
With this change, select() and poll() code paths have the same behavior: saturate the timeout to the implementation maximum. |
@@ -810,7 +810,9 @@ internal_select(PySocketSockObject *s, int writing, PyTime_t interval, | |||
|
|||
/* s->sock_timeout is in seconds, timeout in ms */ | |||
ms = _PyTime_AsMilliseconds(interval, _PyTime_ROUND_CEILING); | |||
assert(ms <= INT_MAX); | |||
if (ms > INT_MAX) { |
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.
Yes, indeed my proposal was wrong. Because later ms
is casted to int
: n = poll(&pollfd, 1, (int)ms);
Thanks for picking this up!
The test fails on Windows:
I modified the test to skip the test if settimeout() raises OverflowError (on Windows). |
Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13. |
…onGH-126968) If the timeout is larger than INT_MAX, replace it with INT_MAX, in the poll() code path. Add an unit test. (cherry picked from commit b3687ad) Co-authored-by: Victor Stinner <vstinner@python.org>
…onGH-126968) If the timeout is larger than INT_MAX, replace it with INT_MAX, in the poll() code path. Add an unit test. (cherry picked from commit b3687ad) Co-authored-by: Victor Stinner <vstinner@python.org>
GH-127002 is a backport of this pull request to the 3.13 branch. |
GH-127003 is a backport of this pull request to the 3.12 branch. |
If the timeout is larger than INT_MAX, replace it with INT_MAX, in the poll() code path.
Add an unit test.
socket
with too large default timeout (larger than INT_MAX) #126876