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-37404: Raising value error if an SSLSocket is passed to asyncio functions #14457
Conversation
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. You can check yourself to see if the CLA has been received. Thanks again for your contribution, we look forward to reviewing it! |
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 introduces a change in behavior which would need a test for respective methods where to assert ValueError
to be raised. The below program with this PR would raise ValueError
. It's already documented at https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.sock_recv that sock should be a non-blocking socket and perhaps need a note about ValueError
.
import socket
import ssl
import asyncio
async def main():
with socket.socket() as sock:
with ssl.wrap_socket(sock) as ssl_socket:
loop = asyncio.get_event_loop()
await loop.sock_recv(ssl_socket, 10)
asyncio.run(main())
./python /tmp/bpo37404.py
Traceback (most recent call last):
File "/tmp/bpo37404.py", line 11, in <module>
asyncio.run(main())
File "/home/karthi/cpython/Lib/asyncio/runners.py", line 43, in run
return loop.run_until_complete(main)
File "/home/karthi/cpython/Lib/asyncio/base_events.py", line 608, in run_until_complete
return future.result()
File "/tmp/bpo37404.py", line 9, in main
await loop.sock_recv(ssl_socket, 10)
File "/home/karthi/cpython/Lib/asyncio/selector_events.py", line 352, in sock_recv
raise ValueError("the socket must not be an SSLSocket instance")
ValueError: the socket must not be an SSLSocket instance
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 believe we need at least one or two Python release with deprecation warning before raising a error.
Otherwise, we break existing code without any notice.
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 |
Aren't deprecation warnings for features that are working right now but won't work in the future? wouldn't sending a deprecation warning give the user a false impression that the sock_recv() function currently works with SSLSocket. |
I have made the requested changes; please review again. |
Thanks for making the requested changes! @asvetlov: please review the changes made to this pull request. |
I have made the requested changes; please review again. |
Thanks for making the requested changes! @asvetlov: please review the changes made to this pull request. |
Lib/asyncio/selector_events.py
Outdated
@@ -341,13 +341,15 @@ def remove_writer(self, fd): | |||
self._ensure_fd_no_transport(fd) | |||
return self._remove_writer(fd) | |||
|
|||
async def sock_recv(self, sock, n): | |||
async def sock_recv(self, sock, n, _warn=warnings.warn): |
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 are you adding new _warn
parameters to methods in this file? That's not necessary.
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.
Fixed
I have made the requested changes; please review again. |
Thanks for making the requested changes! @asvetlov: please review the changes made to this pull request. |
I have made the requested changes; please review again. |
Thanks for making the requested changes! @asvetlov: please review the changes made to this pull request. |
Thanks for the PR, but closing as the CLA has not been signed within the last month. If you do decide to sign the CLA we can re-open this PR. |
https://bugs.python.org/issue37404