Skip to content

Conversation

@tjhowse
Copy link
Contributor

@tjhowse tjhowse commented Feb 2, 2024

Details in #114887

This change is technically incorrect as SOCK_STREAM and SOCK_DGRAM are not actually bitwise comparators.

@ghost
Copy link

ghost commented Feb 2, 2024

The following commit authors need to sign the Contributor License Agreement:

Click the button to sign:
CLA not signed

@bedevere-app
Copy link

bedevere-app bot commented Feb 2, 2024

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 skip news label instead.

if sock.type != socket.SOCK_DGRAM:
if not sock.type & socket.SOCK_DGRAM:
raise ValueError(
f'A UDP Socket was expected, got {sock!r}')
Copy link
Contributor

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.

@gvanrossum
Copy link
Member

gvanrossum commented Feb 2, 2024

I need help with this. I don’t know anything about this part of the socket API — is this assumption universally true?

@tjhowse
Copy link
Contributor Author

tjhowse commented Feb 2, 2024

No, it's not. It appears to be true, and often IS true due a quirk of how the enum is defined, but strictly speaking SOCK_DGRAM and SOCK_STREAM are not intended to be bitmasks. Note @ncoghlan 's comments on #114887. I am closing this PR and will raise a new one with a more appropriate fix.

@tjhowse tjhowse closed this Feb 2, 2024
elif type == socket.SOCK_DGRAM:
elif type & socket.SOCK_DGRAM:
proto = socket.IPPROTO_UDP
else:
Copy link
Contributor

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

Copy link
Contributor Author

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.

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