-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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-32394: Remove some TCP options on old version Windows. #5523
Conversation
Microsoft site says "GetVersionEx may be altered or unavailable for releases after Windows 8.1. Instead, use the Version Helper functions" |
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.
Agreed with @skn78, this should use functions from VersionHelpers.h, not the deprecated GetVersionEx.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Earlier versions of Windows 10 SDK don't have |
Offical The two functions are available in a third part Now I'm inclined to patch in if hasattr(sys, 'getwindowsversion'):
# (new_option, available_build)
# make sure the list ordered by available_build descendent
_new_flags = [
('TCP_KEEPIDLE', 16299), # Windows 10 1709
('TCP_KEEPINTVL', 16299),
('TCP_KEEPCNT', 15063), # Windows 10 1703
('TCP_FASTOPEN', 14393) # Windows 10 1607
]
_WIN_MAJOR, _WIN_MINOR, _WIN_BUILD, *_ = sys.getwindowsversion()
if _WIN_MAJOR == 10 and _WIN_MINOR == 0:
for _flag, _build in _new_flags:
if _WIN_BUILD < _build:
if hasattr(_socket, _flag):
delattr(_socket, _flag)
else:
break
elif _WIN_MAJOR < 10:
for _flag, _ in _new_flags:
if hasattr(_socket, _flag):
delattr(_socket, _flag) |
This PR is prepared for review. Official This PR is conflicts with 3.6 branch code. |
Comment addressed; not qualified for full review.
@zware
But I can't found any comment, this make me feel very embarrassed. |
Look just above the message from @bedevere-bot for my old review comment, which was just formalization of the comment left by @skn78 and which you have addressed already. I'm afraid that's about the extent of my ability to review this one, though. |
ok |
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.
There's nothing really wrong here, just a few suggestions and some code-quality items that we really can't let through (I don't think we have linting for them, and we probably can't add it easily at this stage, but newer projects would simply forbid mis-named methods).
Lib/test/test_socket.py
Outdated
'TCP_KEEPINTVL' | ||
} | ||
|
||
def testNewTCPFlags(self): |
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.
Please use words_with_underscores
style for new test names.
Lib/test/test_socket.py
Outdated
"see issue32394.\n" | ||
"Full avaliable TCP flags on this system: %s" | ||
) % (unknown, provided) | ||
raise Exception(msg) |
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.
This can be as simple as:
self.assertEqual([], unknown, "New TCP flags were discovered. See bpo-32394 for more information")
Modules/socketmodule.c
Outdated
info.dwBuildNumber = flags[i].build_number; | ||
/* greater than or equal to the specified version? | ||
Compatibility Mode will not cheat VerifyVersionInfo(...) */ | ||
if (VerifyVersionInfo( |
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.
The IsWindowsVersionOrGreater
function should always be available, which will simplify this call.
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.
IsWindowsVersionOrGreater
is only aware of MajorVersion
, MinorVersion
, ServicePackMajor
. While we need to compare BuildNumber
.
IsWindowsVersionOrGreater
uses VerifyVersionInfo
in the inner side, I'm also using this function, but made it aware of MajorVersion
, MinorVersion
, BuildNumber
, these three fields fit in with our task.
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.
To make sure it works, I have tested here in several ways:
- change
build_number
in the array. - change
info.dwMajorVersion
andinfo.dwMinorVersion
. - operate
setsockopt()
,getsockopt()
under Compatibility Mode. - upset the order of macro
VER_SET_CONDITION()
.
Modules/socketmodule.c
Outdated
@@ -305,6 +305,69 @@ if_indextoname(index) -- return the corresponding interface name\n\ | |||
/* Provides the IsWindows7SP1OrGreater() function */ | |||
#include <VersionHelpers.h> | |||
|
|||
/* This block removes some flags on older version Windows during run-time. | |||
https://msdn.microsoft.com/en-us/library/windows/desktop/ms738596.aspx */ | |||
#if 1 |
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.
No need for the #if 1
(I assume this is already within an MS_WINDOWS
block)
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.
I thought some IDEs can fold this code block, I removed it.
Modules/socketmodule.c
Outdated
} FlagRuntimeInfo; | ||
|
||
/* IMPORTANT: make sure the list ordered by descending build_number */ | ||
static FlagRuntimeInfo flags[] = { |
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.
This is a big module - using a name more like tcp_flag_windows_version
will avoid conflicts with other parts.
Modules/socketmodule.c
Outdated
@@ -7883,5 +7946,10 @@ PyInit__socket(void) | |||
#if defined(USE_GETHOSTBYNAME_LOCK) || defined(USE_GETADDRINFO_LOCK) | |||
netdb_lock = PyThread_allocate_lock(); | |||
#endif | |||
|
|||
#ifdef MS_WINDOWS | |||
return remove_unusable_flags(m); |
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.
Make this remove_unusable_flags(m)
and then leave the return
outside the if
block (it's easier to reason about an optional action than a potential transformation, and the same object is always returned)
I have modified, sorry for my unskillful patch. |
Thanks @animalize for the PR, and @zooba for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7. |
GH-5910 is a backport of this pull request to the 3.7 branch. |
Sorry, @animalize and @zooba, I could not cleanly backport this to |
GH-5585 is a backport of this pull request to the 3.6 branch. |
Thanks @animalize! |
https://bugs.python.org/issue32394
https://bugs.python.org/issue32394