Sometimes when a socket transport under ProactorEventLoop is writing while the peer closes the connection, asyncio logs an AssertionError.
Attached is a script that fairly reliably reproduces the behavior on my computer.
This is caused by _ProactorBasePipeTransport._force_close() being called between two invocations of _ProactorBaseWritePipeTransport._loop_writing(), where the latter call asserts self._write_fut has not changed after being set by the former call.
Sometimes when a socket transport under ProactorEventLoop is writing while the peer closes the connection, asyncio logs an AssertionError.
Would you mind to add an example of such error in this issue?
twisteroidambassador commented on Jun 28, 2018
twisteroidambassadormannequin
MannequinAuthor
More actions
No problem. Running the attached test script on latest master, Windows 10 1803, several errors like this are logged:
Exception in callback _ProactorBaseWritePipeTransport._loop_writing(<_OverlappedF...events.py:479>)
handle: <Handle _ProactorBaseWritePipeTransport._loop_writing(<_OverlappedF...events.py:479>) created at %USERPROFILE%\source\repos\cpython\lib\asyncio\proactor_events.py:373>source_traceback: Object created at (most recent call last):
File "%USERPROFILE%\source\repos\cpython\lib\asyncio\base_events.py", line 555, in run_until_completeself.run_forever()
File "%USERPROFILE%\source\repos\cpython\lib\asyncio\base_events.py", line 523, in run_foreverself._run_once()
File "%USERPROFILE%\source\repos\cpython\lib\asyncio\base_events.py", line 1750, in _run_once
handle._run()
File "%USERPROFILE%\source\repos\cpython\lib\asyncio\events.py", line 88, in _runself._context.run(self._callback, *self._args)
File "..\..\..\..\Documents\python\test_proactor_force_close.py", line 8, in server_callback
writer.write(b'hello')
File "%USERPROFILE%\source\repos\cpython\lib\asyncio\streams.py", line 305, in writeself._transport.write(data)
File "%USERPROFILE%\source\repos\cpython\lib\asyncio\proactor_events.py", line 334, in writeself._loop_writing(data=bytes(data))
File "%USERPROFILE%\source\repos\cpython\lib\asyncio\proactor_events.py", line 373, in _loop_writingself._write_fut.add_done_callback(self._loop_writing)
Traceback (most recent call last):
File "%USERPROFILE%\source\repos\cpython\lib\asyncio\events.py", line 88, in _runself._context.run(self._callback, *self._args)
File "%USERPROFILE%\source\repos\cpython\lib\asyncio\proactor_events.py", line 346, in _loop_writingassert f isself._write_fut
AssertionError
twisteroidambassador commented on Jun 28, 2018
twisteroidambassadormannequin
MannequinAuthor
More actions
As an aside, I'm wondering whether it makes sense to add a blanket "assert exception handler has not been called" condition to ProactorEventLoop's tests, or even other asyncio tests. It looks like ProactorEventLoop is more prone to dropping exceptions on the floor than SelectorEventLoop.
New changeset 9045199 by Andrew Svetlov (twisteroid ambassador) in branch 'master': bpo-33833: Fix ProactorSocketTransport AssertionError (bpo-7893) 9045199
Activity
twisteroidambassador commented on Jun 11, 2018
Sometimes when a socket transport under ProactorEventLoop is writing while the peer closes the connection, asyncio logs an AssertionError.
Attached is a script that fairly reliably reproduces the behavior on my computer.
This is caused by _ProactorBasePipeTransport._force_close() being called between two invocations of _ProactorBaseWritePipeTransport._loop_writing(), where the latter call asserts self._write_fut has not changed after being set by the former call.
1st1 commented on Jun 11, 2018
Adding Victor as he's been helping with asyncio/proactor lately.
vstinner commented on Jun 27, 2018
Would you mind to add an example of such error in this issue?
twisteroidambassador commented on Jun 28, 2018
No problem. Running the attached test script on latest master, Windows 10 1803, several errors like this are logged:
twisteroidambassador commented on Jun 28, 2018
As an aside, I'm wondering whether it makes sense to add a blanket "assert exception handler has not been called" condition to ProactorEventLoop's tests, or even other asyncio tests. It looks like ProactorEventLoop is more prone to dropping exceptions on the floor than SelectorEventLoop.
asvetlov commented on Jul 30, 2018
New changeset 9045199 by Andrew Svetlov (twisteroid ambassador) in branch 'master':
bpo-33833: Fix ProactorSocketTransport AssertionError (bpo-7893)
9045199
miss-islington commented on Jul 30, 2018
New changeset d5c75be by Miss Islington (bot) in branch '3.7':
bpo-33833: Fix ProactorSocketTransport AssertionError (GH-7893)
d5c75be
vstinner commented on Jul 30, 2018
Why not fixing Python 3.6? It is not affected?
BoilingNine commented on Oct 17, 2024
I still get this problem when I call asyncio.run from a child thread in a loop
vstinner commented on Oct 17, 2024
Please open a new issue, this issue is now closed.