8000 [3.10] bpo-41710: Fix PY_TIMEOUT_MAX value on Windows by vstinner · Pull Request #28672 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.10] bpo-41710: Fix PY_TIMEOUT_MAX value on Windows #28672

8000 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

Closed
wants to merge 1 commit into from
Closed

[3.10] bpo-41710: Fix PY_TIMEOUT_MAX value on Windows #28672

wants to merge 1 commit into from

Conversation

vstinner
Copy link
Member
@vstinner vstinner commented Oct 1, 2021

Fix _thread.TIMEOUT_MAX value on Windows: the maximum timeout is
0x7FFFFFFF milliseconds (around 24.9 days), not 0xFFFFFFFF
milliseconds (around 49.7 days).

Set PY_TIMEOUT_MAX to 0x7FFFFFFF milliseconds, rather than 0xFFFFFFFF
milliseconds.

https://bugs.python.org/issue41710

Fix _thread.TIMEOUT_MAX value on Windows: the maximum timeout is
0x7FFFFFFF milliseconds (around 24.9 days), not 0xFFFFFFFF
milliseconds (around 49.7 days).

Set PY_TIMEOUT_MAX to 0x7FFFFFFF milliseconds, rather than 0xFFFFFFFF
milliseconds.
@vstinner
Copy link
Member Author
vstinner commented Oct 1, 2021

Oh, I read WaitForSingleObject documentation of 2006 for Windows CE 3.0:
https://docs.microsoft.com/en-us/previous-versions/ms915517(v=msdn.10)

The time-out value needs to be a positive number between 0 and 0x7FFFFFFF. The maximum time-out value not equal to infinity is 0x7FFFFFFF. The infinite time-out value is 0xFFFFFFFF. Any time-out value between 0x7FFFFFFF and 0xFFFFFFFF—that is, values from 0xF0000000 through 0xFFFFFFFE—is equivalent to 0x7FFFFFFF. If you need a bigger time-out value than the maximum of 0x7FFFFFFF, use the value for infinity (0xFFFFFFFF).

Maybe this is different on Windows 10 and my change in the main branch is not correct.

@vstinner
Copy link
Member Author
vstinner commented Oct 1, 2021

In ReactOS, WaitForSingleObject() calls WaitForSingleObjectEx() which converts "DWORD dwMilliseconds" to "LARGE_INTEGER Time" with BaseFormatTimeOut()

 PLARGE_INTEGER
 WINAPI
 BaseFormatTimeOut(OUT PLARGE_INTEGER Timeout,
                   IN DWORD dwMilliseconds)
 {
     /* Check if this is an infinite wait, which means no timeout argument */
     if (dwMilliseconds == INFINITE) return NULL;
 
     /* Otherwise, convert the time to NT Format */
     Timeout->QuadPart = dwMilliseconds * -10000LL;
     return Timeout;
 }

Then WaitForSingleObjectEx() calls NtWaitForSingleObject() with the "LARGE_INTEGER Time".

So I don't see any special case for values in the [0x80000000; 0xFFFFFFFE] range. Only INFINITE is special. In ReactOS, INFINITE is defined as:

#define INFINITE MAXULONG

I understand that INFINITE is equal to 0xFFFFFFFF.

@vstinner
Copy link
Member Author
vstinner commented Oct 1, 2021

The code in the main branch, I wrote PR #28673 to fix it instead.

@vstinner vstinner closed this Oct 1, 2021
@vstinner vstinner deleted the timeout_max branch October 1, 2021 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0