Skip to content

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

Closed
vstinner wants to merge 1 commit into
python:3.10from
vstinner:timeout_max
Closed

[3.10] bpo-41710: Fix PY_TIMEOUT_MAX value on Windows#28672
vstinner wants to merge 1 commit into
python:3.10from
vstinner:timeout_max

Conversation

@vstinner

@vstinnervstinner commented Oct 1, 2021

Copy link
Copy Markdown
Member

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
Copy Markdown
MemberAuthor

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
Copy Markdown
MemberAuthor

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
Copy Markdown
MemberAuthor

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

@vstinnervstinner closed this Oct 1, 2021
@vstinner
vstinner deleted the timeout_max branch October 1, 2021 09:26
Sign up for freeto 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

@vstinner@the-knights-who-say-ni@bedevere-bot