Created on 2017-03-06 22:35 by fafhrd91, last changed 2022-04-11 14:58 by admin. This issue is now closed.
https://github.com/python/asyncio/issues/494
exception on get_extra_info() on closed ssl transport ``` Feb 18 13:18:09 btc electrumx_server.py[1732]: ERROR:ElectrumX:[15328] Traceback (most recent call last): Feb 18 13:18:09 btc electrumx_server.py[1732]: File "/usr/local/lib/python3.5/dist-packages/electrumx-0.11.1-py3.5.egg/lib/jsonrpc.py", line 528, in process_single_request Feb 18 13:18:09 btc electrumx_server.py[1732]: result = await self.handle_payload(payload, self.request_handler) Feb 18 13:18:09 btc electrumx_server.py[1732]: File "/usr/local/lib/python3.5/dist-packages/electrumx-0.11.1-py3.5.egg/lib/jsonrpc.py", line 608, in handle_payload Feb 18 13:18:09 btc electrumx_server.py[1732]: return await handler(**kw_args) Feb 18 13:18:09 btc electrumx_server.py[1732]: File "/usr/local/lib/python3.5/dist-packages/electrumx-0.11.1-py3.5.egg/server/session.py", line 282, in banner Feb 18 13:18:09 btc electrumx_server.py[1732]: if self.is_tor(): Feb 18 13:18:09 btc electrumx_server.py[1732]: File "/usr/local/lib/python3.5/dist-packages/electrumx-0.11.1-py3.5.egg/server/session.py", line 259, in is_tor Feb 18 13:18:09 btc electrumx_server.py[1732]: peer_info = self.peer_info() Feb 18 13:18:09 btc electrumx_server.py[1732]: File "/usr/local/lib/python3.5/dist-packages/electrumx-0.11.1-py3.5.egg/lib/jsonrpc.py", line 764, in peer_info Feb 18 13:18:09 btc electrumx_server.py[1732]: return self.transport.get_extra_info('peername') Feb 18 13:18:09 btc electrumx_server.py[1732]: File "/usr/lib/python3.5/asyncio/sslproto.py", line 306, in get_extra_info Feb 18 13:18:09 btc electrumx_server.py[1732]: return self._ssl_protocol._get_extra_info(name, default) Feb 18 13:18:09 btc electrumx_server.py[1732]: File "/usr/lib/python3.5/asyncio/sslproto.py", line 537, in _get_extra_info Feb 18 13:18:09 btc electrumx_server.py[1732]: return self._transport.get_extra_info(name, default) Feb 18 13:18:09 btc electrumx_server.py[1732]: AttributeError: 'NoneType' object has no attribute 'get_extra_info' ```
Thanks for the report and PR, but your fix is not obviously correct. In general exceptions are the way in Python that errors are reported, and asking for extra_info on a closed stream is an error. The exception raised is not clear, so perhaps the asyncio folks will want to improve it. Or perhaps I'm wrong and they will want to return None, but I'll be a bit surprised if that is the case :)
get_extra_info() returns optional transport information, I think it is ok to return None for closed transport. https://github.com/python/cpython/blob/master/Lib/asyncio/transports.py#L18 I propose this feature initially, during early tulip development but now I think it is not good api.
> Thanks for the report and PR, but your fix is not obviously correct. Not for this particular asyncio method though, see asyncio PEP [1]. But there's an actual bug in the PR, instead of returning `None` we should return `default`. [1] https://www.python.org/dev/peps/pep-3156/#methods-for-all-transports
New changeset db522dc86294a99f46a63cd5b54c7c4ab8017c96 by Yury Selivanov in branch '3.5': bpo-29742: asyncio get_extra_info() throws exception (#525) (#646) https://github.com/python/cpython/commit/db522dc86294a99f46a63cd5b54c7c4ab8017c96
New changeset 99f8d33a94c8951fd6b2d5f079d20be698150993 by Yury Selivanov in branch '3.6': bpo-29742: asyncio get_extra_info() throws exception (#525) (#645) https://github.com/python/cpython/commit/99f8d33a94c8951fd6b2d5f079d20be698150993
New changeset 2b27e2e6a35c3d3e369612b984017fe0d1bfcf0c by Yury Selivanov (Nikolay Kim) in branch 'master': bpo-29742: asyncio get_extra_info() throws exception (#525) https://github.com/python/cpython/commit/2b27e2e6a35c3d3e369612b984017fe0d1bfcf0c