On 24/05/16 03:19 AM, Victor Stinner wrote:
2016-05-23 18:19 GMT+02:00 Jack Bates <[email protected]>:
Can you help me understand why _SelectorTransport.__del__()
is called before _SSLProtocolTransport.__del__()?

Are you using the debug mode of asyncio?
https://docs.python.org/dev/library/asyncio-dev.html#debug-mode-of-asyncio

asyncio now emits ResourceWarning warnings when transports are not
closed explicitly. It looks like you forgot to close explicitly a
transport.

Fatal write error on socket transport

By the way, do you know why the write failed? Did you close manually
the socket without notifying asyncio?

The socket is closed in _SelectorTransport.__del__()
(commit 241c71030cb79217bd6be6f6dfe31e87bc5f6cbf)

So if _SelectorTransport.__del__() is called before _SSLProtocolTransport.__del__() the result is this fatal error.

I'm pretty sure I should merely get a ResourceWarning
(not a fatal error) but I wonder whether the problem is that _SSLProtocolTransport.__del__() should be called first,
or that they should handle being called in this order?

The following script reproduces the error for me:


nottheoilrig@debian:~$ cat script.py
import asyncio

asyncio.get_event_loop().run_until_complete(asyncio.open_connection('google.com', 'https', ssl=True))
nottheoilrig@debian:~$ python3 script.py
Fatal write error on socket transport
protocol: <asyncio.sslproto.SSLProtocol object at 0x7fbeb1975c50>
transport: <_SelectorSocketTransport fd=6>
Traceback (most recent call last):
  File "/usr/lib/python3.5/asyncio/selector_events.py", line 700, in write
    n = self._sock.send(data)
OSError: [Errno 9] Bad file descriptor
Exception ignored in: <bound method _SSLProtocolTransport.__del__ of <asyncio.sslproto._SSLProtocolTransport object at 0x7fbeb1975b00>>
Traceback (most recent call last):
  File "/usr/lib/python3.5/asyncio/sslproto.py", line 328, in __del__
  File "/usr/lib/python3.5/asyncio/sslproto.py", line 319, in close
File "/usr/lib/python3.5/asyncio/sslproto.py", line 542, in _start_shutdown File "/usr/lib/python3.5/asyncio/sslproto.py", line 547, in _write_appdata File "/usr/lib/python3.5/asyncio/sslproto.py", line 651, in _process_write_backlog
  File "/usr/lib/python3.5/asyncio/sslproto.py", line 658, in _fatal_error
NameError: name 'base_events' is not defined
nottheoilrig@debian:~$

Reply via email to