classification
Title: test_asyncio: test_drain_raises() fails randomly on Windows
Type: Stage: resolved
Components: asyncio, Tests Versions: Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, pablogsal, terry.reedy, vstinner, yselivanov
Priority: normal Keywords:

Created on 2019-05-10 00:57 by vstinner, last changed 2019-06-04 12:59 by vstinner. This issue is now closed.

Messages (10)
msg342023 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-05-10 00:57
https://ci.appveyor.com/project/python/cpython/builds/24376676

ERROR: test_drain_raises (test.test_asyncio.test_streams.StreamTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\projects\cpython\lib\test\test_asyncio\test_streams.py", line 820, in test_drain_raises
    self.loop.run_until_complete(client(*addr))
  File "C:\projects\cpython\lib\asyncio\base_events.py", line 584, in run_until_complete
    return future.result()
  File "C:\projects\cpython\lib\test\test_asyncio\test_streams.py", line 810, in client
    await writer.drain()
  File "C:\projects\cpython\lib\asyncio\streams.py", line 351, in drain
    await fut
  File "C:\projects\cpython\lib\asyncio\selector_events.py", line 860, in write
    n = self._sock.send(data)
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine
msg342357 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2019-05-13 16:37
I have gotten this too, multiple times, on both Azure Pipelines and Appveyor.  The latter is worse since required.  There was also a Mac failure for Azure, not sure is same issue.

Please disable this test.  External resource problems should not be blocking merges of good patches.  This is especially obnoxious for backports because it is not possible to rerun by close and reopen, as closing causes the backport branch to be deleted.
msg342462 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-05-14 14:01
Maybe the test started to fail randomly after this change:

commit 1cc0ee7d9f6a2817918fafd24c18d8bb093a85d3
Author: Andrew Svetlov <andrew.svetlov@gmail.com>
Date:   Tue May 7 16:53:19 2019 -0400

    bpo-36801: Fix waiting in StreamWriter.drain for closing
    SSL transport (GH-13098)

The test is quite old, added in bpo-25441:

commit c44ecdf687897a20f11d0c5212b51e8d31f6100a
Author: Guido van Rossum <guido@python.org>
Date:   Mon Oct 19 11:49:30 2015 -0700

    Issue #25441: asyncio: Raise error from drain() when socket is closed.
msg342467 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-05-14 14:35
Another candidate:

commit a076e4f5e42b85664693191d04cfb33e2f9acfa5 (refs/bisect/bad) 
Author: Andrew Svetlov <andrew.svetlov@gmail.com>
Date:   Thu May 9 15:14:58 2019 -0400

    bpo-36802: Drop awrite()/aclose(), support await write() and await close() instead (#13099)

Before this commit, the test pass. After this commit, the test still pass but logs a warning:

vstinner@WIN C:\vstinner\python\master>python -m test test_asyncio -m test_drain_raises -v
(...)
test_drain_raises (test.test_asyncio.test_streams.StreamTests) ... Task exception was never retrieved
future: <Task finished name='Task-2' coro=<StreamWriter.drain() done, defined at C:\vstinner\python\master\lib\asyncio\streams.py:417> exception=ConnectionAbor
tedError(10053, 'An established connection was aborted by the software in your host machine', None, 10053, None)>
Traceback (most recent call last):
  File "C:\vstinner\python\master\lib\asyncio\streams.py", line 434, in drain
    await fut
  File "C:\vstinner\python\master\lib\asyncio\proactor_events.py", line 370, in _loop_writing
    self._write_fut = self._loop._proactor.send(self._sock, data)
  File "C:\vstinner\python\master\lib\asyncio\windows_events.py", line 488, in send
    ov.WSASend(conn.fileno(), buf, flags)
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine
ok
(...)
Tests result: SUCCESS
msg342472 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-05-14 15:24
I wrote PR 13316 to revert the commit a076e4f5e42b85664693191d04cfb33e2f9acfa5 of bpo-36802:
https://bugs.python.org/issue36802#msg342471
msg342476 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2019-05-14 15:32
Please postpone the reversion for a while.
I think #36916 fixes a message about the never retrieved exception.
msg342509 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-05-14 20:08
PR 13313 has been merged into master. Let's see if it does fix this issue in master.

Python 3.7 is different: streams.py doesn't have _fast_drain() which was added by commit a076e4f5e42b85664693191d04cfb33e2f9acfa5 (bpo-36802). So instead, I created PR 13328 to revert the commit 93aa57ac6594d1cc30d147720fc8a7a4e1ca2d3e of bpo-36801, to get more time to find a proper fix to Python 3.7.
msg342510 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2019-05-14 20:11
Agree with your conclusion
msg342517 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-05-14 20:37
"""
commit 1cc0ee7d9f6a2817918fafd24c18d8bb093a85d3
Author: Andrew Svetlov <andrew.svetlov@gmail.com>
Date:   Tue May 7 16:53:19 2019 -0400

    bpo-36801: Fix waiting in StreamWriter.drain for closing
    SSL transport (GH-13098)
"""

I reverted this change in 3.7:

commit c647ad9b51c59f71c02cd90c5e67d1b2768323ca (HEAD -> 3.7, upstream/3.7)
Author: Victor Stinner <victor.stinner@gmail.com>
Date:   Tue May 14 22:29:54 2019 +0200

    Revert "bpo-36801: Fix waiting in StreamWriter.drain for closing SSL transport (GH-13098)" (GH-13328)
    
    This reverts commit 93aa57ac6594d1cc30d147720fc8a7a4e1ca2d3e.

Without this revert, I was able to easily reproduce the failure. With the revert, I cannot reproduce it anymore:
https://github.com/python/cpython/pull/13328#issuecomment-492394753
msg342522 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-05-14 21:44
Andrew merged https://github.com/python/cpython/pull/13330 into master, it should fix this issue.
History
Date User Action Args
2019-06-04 12:59:47vstinnersetstatus: open -> closed
resolution: fixed
stage: resolved
2019-05-14 21:44:37vstinnersetmessages: + msg342522
2019-05-14 20:37:01vstinnersetmessages: + msg342517
2019-05-14 20:11:32asvetlovsetmessages: + msg342510
2019-05-14 20:08:12vstinnersetmessages: + msg342509
2019-05-14 15:32:40asvetlovsetmessages: + msg342476
2019-05-14 15:24:07vstinnersetmessages: + msg342472
2019-05-14 14:35:37vstinnersetmessages: + msg342467
2019-05-14 14:01:56vstinnersetmessages: + msg342462
2019-05-13 16:37:21terry.reedysetnosy: + terry.reedy
messages: + msg342357
2019-05-11 18:11:28xtreaksetnosy: + asvetlov, yselivanov
components: + asyncio
2019-05-10 00:57:51vstinnercreate