This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: asyncio get_extra_info() throws exception
Type: Stage: resolved
Components: asyncio Versions: Python 3.7, Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: fafhrd91, r.david.murray, yselivanov
Priority: normal Keywords:

Created on 2017-03-06 22:35 by fafhrd91, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 494 fafhrd91, 2017-03-06 22:35
PR 525 merged fafhrd91, 2017-03-06 23:36
PR 645 merged yselivanov, 2017-03-12 19:29
PR 646 merged yselivanov, 2017-03-12 19:30
PR 703 larry, 2017-03-17 21:00
Messages (8)
msg289138 - (view) Author: Nikolay Kim (fafhrd91) * Date: 2017-03-06 22:35
https://github.com/python/asyncio/issues/494
msg289139 - (view) Author: Nikolay Kim (fafhrd91) * Date: 2017-03-06 22:37
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'
```
msg289140 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-03-06 22:44
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 :)
msg289141 - (view) Author: Nikolay Kim (fafhrd91) * Date: 2017-03-06 22:49
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.
msg289142 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2017-03-06 22:50
> 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
msg290192 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2017-03-24 22:21
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
msg290193 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2017-03-24 22:21
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
msg290196 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2017-03-24 22:21
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
History
Date User Action Args
2022-04-11 14:58:43adminsetgithub: 73928
2017-03-24 22:21:52yselivanovsetmessages: + msg290196
2017-03-24 22:21:26yselivanovsetmessages: + msg290193
2017-03-24 22:21:21yselivanovsetmessages: + msg290192
2017-03-17 21:00:33larrysetpull_requests: + pull_request596
2017-03-12 21:06:52yselivanovsetstatus: open -> closed
resolution: fixed
stage: resolved
2017-03-12 19:30:20yselivanovsetpull_requests: + pull_request535
2017-03-12 19:29:56yselivanovsetpull_requests: + pull_request534
2017-03-06 23:40:52gvanrossumsetnosy: - gvanrossum
2017-03-06 23:36:42fafhrd91setpull_requests: + pull_request438
2017-03-06 22:50:39yselivanovsetmessages: + msg289142
2017-03-06 22:49:12fafhrd91setmessages: + msg289141
2017-03-06 22:44:24r.david.murraysetnosy: + r.david.murray, gvanrossum, yselivanov
messages: + msg289140
components: + asyncio
2017-03-06 22:37:31fafhrd91setmessages: + msg289139
2017-03-06 22:35:43fafhrd91create