-
-
Notifications
You must be signed in to change notification settings - Fork 184
Check to see if SO_REUSEPORT is usable and not just defined. #418
Conversation
asyncio/base_events.py
Outdated
| socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | ||
| if reuse_port: | ||
| if not hasattr(socket, 'SO_REUSEPORT'): | ||
| if not hasattr(socket, "SO_REUSEPORT") or \ |
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.
Why can't you use just if not _HAS_USABLE_SO_REUSEPORT:?
(Also, please don't use \ for continuations, use an extra pair of (). PEP 8 please!
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.
Because of all the mock patching in the test cases. Patching the socket module in the *_test_nosoreuseport prevents that atm. And I will change the bracing.
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.
Switched the order of the check, should still pass tests but also will not have to check hasattr() each call in real use.
|
I think those tests need to be fixed then. There should be only one way to test for SO_REUSEPORT. |
|
@gvanrossum Alternative is to do the check inline when the reuse_port option is specified? Wouldn't be a performance hit as create_server and create_unix_server probably get used once and forgotten. |
|
Hm, maybe just catch the exception and translate it into the same ValueError (actually a slightly similar message so we can tell the difference). |
|
@gvanrossum I switched to catching the exception inline, I also added a test to test an ill-defined SO_REUSEPORT as with the issue this PR fixes. |
|
LGTM now. @1st1 what do you think? |
|
LGTM. Can we merge this after b1? |
|
This also closes issue #352 as mentioned above. Can be closed if accepted but awaiting merge? |
|
Will merge (here and in CPython) after 3.6b1.
|
|
Pushed in 610c03f. Thanks! |
|
See also https://hg.python.org/cpython/rev/c1c247cf3488/. Looks like this is your first commit to CPython, congrats if so! BTW, did you sign Python Contributor Agreement? |
|
@1st1 Thank you! This is my first commit and I signed it the day I submitted this PR. See my comment above in the PR. |
|
I am sorry, but to me this fix actually causes more problems than it fixes. Yes, the old error message is rather cryptic and the new exception message is way better, but changing the exception type seems wrong to me. Yes,
My recommendation would be to catch the old |
|
@Dakkaron I made this change for consistency reasons so that trying to use If you think this should be changed you can raise an issue on the Python tracker. |
|
Sorry, my bad, I didn't notice that the old version already raised a |
|
Glad I could clarify. :) |
Some platforms define SO_REUSEPORT but do not implement it, resulting in cryptic OSErrors when trying to use socket.SO_REUSEPORT. This PR would solve that issue for all platforms that implement but don't define a usable SO_REUSEPORT. More info in Python issue 26858. See issue #352 .
Edit: I have signed the PSF Contributor Agreement