Skip to content
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

SocketStream.receive sometimes returns bytearray objects on Windows #776

Closed
2 tasks done
jonathanslenders opened this issue Aug 30, 2024 · 2 comments · Fixed by #777
Closed
2 tasks done

SocketStream.receive sometimes returns bytearray objects on Windows #776

jonathanslenders opened this issue Aug 30, 2024 · 2 comments · Fixed by #777
Labels
bug Something isn't working

Comments

@jonathanslenders
Copy link
Contributor

Things to check first

  • I have searched the existing issues and didn't find my bug already reported there

  • I have checked that my bug is still present in the latest release

AnyIO version

4.4.0

Python version

3.11

What happened?

StreamProtocol, here: https://github.com/agronholm/anyio/blob/master/src/anyio/_backends/_asyncio.py#L1075
incorrectly assumes that it will only get bytes objects as an argument. Unfortunately, on Windows, that's not the case. For the ProactorEventLoop, we'll get bytearray objects here.

See:

I think the quickest fix for anyio is to accept bytearray as well, and convert it into bytes, regardless of what typeshed/cpython do.

How can we reproduce the bug?

(Sorry, I don't have access to a Windows machine right now to create an example, but please let me know if an example script is needed.)

@jonathanslenders jonathanslenders added the bug Something isn't working label Aug 30, 2024
@jonathanslenders
Copy link
Contributor Author

It looks like it was fixed in cpython v3.12.0a4 thanks to this commit:
python/cpython@1bb68ba

However, it would still be good to handle the issue here for Python 3.10 and 3.11. (3.9 doesn't have the issue).

@agronholm
Copy link
Owner

Review welcome. As I mentioned in the CPython issue, I was able to locally reproduce this even on the latest 3.12 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants