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
Inconsistent behavior of asyncio.Transport.get_extra_info("peername") on TLS vs. non-TLS connections #91635
Comments
Tested on 3.11: TLS transport does not return cpython/Lib/asyncio/sslproto.py Lines 484 to 490 in 3289209
However non-TLS transport does not wrap another transport so it continues to return in this case |
I am not sure if this a bug. After closing the transport, I don't think you can expect to get connection information, otherwise this has other unwanted consequences as the ssl context is destroyed so you cannot ssl ciphers etc. I would say you get all the info once connection is made and don't rely on this implementation detail. |
Would like to hear from @aaugustin about the use case before we close this. |
Hello, you can find the original use case in the aforementioned issue: aaugustin/websockets#1136 So, if an application wants this info after the connection is closed, it has to be cached at one of the following three levels: A. standard library (Python) Currently, the answer is "A. for plain TCP connections, C. for TCP + TLS connections". This behavior appears to be an implementation detail rather than an intentional behavior. So we're in Hyrum's law territory.... It could be better to raise an exception when In the end, I don't care which choice we make: websockets will promise exactly what Python promises. It will be zero effort for me in all cases :-) |
PR #98563 adds clarification that transports should not be used after they are closed. IMO a doc update is enough for this. |
…ythonGH-98563) (cherry picked from commit 2fdcc6f) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
…ythonGH-98563) (cherry picked from commit 2fdcc6f) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Marking as not planned since we decided to keep the existing inconsistent behavior, and just document that you shouldn't do that. |
aaugustin commentedApr 17, 2022
Bug report
After an
asyncio.Transport
is closed,transport.get_extra_info("peername")
still returns the remote address if it's a non-TLS transport, while it doesn't return anything when it's a TLS transport. This inconsistency is surprising.By TLS transport, I mean
<class 'asyncio.sslproto._SSLProtocolTransport'>
and by non-TLS transport, I mean<class 'asyncio.selector_events._SelectorSocketTransport'>
. I observed this behavior on macOS.Setup
Test with TLS
Note that the second
transport.get_extra_info("peername")
doesn't return anything.Test without TLS
Note that the second
transport.get_extra_info("peername")
still returns the address.Your environment
The text was updated successfully, but these errors were encountered: