-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-114887: Perform bitwise comparisons with SOCK_DGRAM and SOCK_STEAM #114888
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
Conversation
The following commit authors need to sign the Contributor License Agreement: |
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
@@ -1340,7 +1340,7 @@ async def create_datagram_endpoint(self, protocol_factory, | |||
allow_broadcast=None, sock=None): | |||
"""Create datagram connection.""" | |||
if sock is not None: | |||
if sock.type != socket.SOCK_DGRAM: | |||
if not sock.type & socket.SOCK_DGRAM: | |||
raise ValueError( | |||
f'A UDP Socket was expected, got {sock!r}') |
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 error message should also change.
I need help with this. I don’t know anything about this part of the socket API — is this assumption universally true? |
proto = socket.IPPROTO_TCP | ||
elif type == socket.SOCK_DGRAM: | ||
elif type & socket.SOCK_DGRAM: | ||
proto = socket.IPPROTO_UDP | ||
else: |
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.
Continuing to exclude SOCK_RAW here actually seems like the right thing to do (since raw sockets don't have IP addresses).
If omitting this part of the change doesn't fix the original bug report, then I'd suggest adding SOCK_RAW
as its own branch saying something like:
elif type == socket.SOCK_RAW:
# asyncio mishandles raw sockets if `_ipaddr_info` returns `None`,
# so fib about the underlying protocol
proto = socket.IPPROTO_UDP
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 change isn't required to fix our specific problem. I feel fewer side effects would come from preserving the current behaviour.
Details in #114887
This change is technically incorrect as SOCK_STREAM and SOCK_DGRAM are not actually bitwise comparators.