classification
Title: _ProactorBasePipeTransport.abort() after _ProactorBasePipeTransport.close() does not cancel writes
Type: Stage:
Components: asyncio Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, graingert, gvanrossum, lukasz.langa, yselivanov
Priority: normal Keywords:

Created on 2021-06-15 21:00 by graingert, last changed 2021-07-12 16:40 by graingert.

Messages (2)
msg395896 - (view) Author: Thomas Grainger (graingert) * Date: 2021-06-15 21:00
demo program:

import asyncio
import socket
import threading

async def amain():
    family = socket.AddressFamily.AF_INET
    sock = socket.socket(family, socket.SOCK_STREAM)
    sock.settimeout(1)
    sock.bind(('localhost', 0))
    sock.listen()
    host, port = sock.getsockname()[:2]

    event = threading.Event()

    def serve():
        client, _ = sock.accept()
        with client:
            client.recv(1)
            event.wait()

    t = threading.Thread(target=serve, daemon=True)
    t.start()

    reader, writer = await asyncio.open_connection(host=host, port=port)
    try:
        while True:
            writer.write(b"\x00" * 4096 * 682 * 2)
            await asyncio.wait_for(writer.drain(), 2)
            print("wrote")
    except asyncio.TimeoutError:
        print("timed out")

    writer.close()
    await asyncio.sleep(0)
    writer.transport.abort()
    print("waiting close")
    await writer.wait_closed()  # never finishes on ProactorEventLoop
    print("closed")
    event.set()
    t.join()

asyncio.run(amain())

it looks like it was fixed for the selector eventloop in https://github.com/python/cpython/commit/2546a177650264205e8a52b6836bc5b8c48bf085

but not for the proactor https://github.com/python/cpython/blame/8fe57aacc7bf9d9af84803b69dbb1d66597934c6/Lib/asyncio/proactor_events.py#L140
msg396558 - (view) Author: Thomas Grainger (graingert) * Date: 2021-06-26 22:44
nosying the author of the selector_events fix
History
Date User Action Args
2021-07-12 16:40:18graingertsetnosy: + lukasz.langa
2021-06-26 22:44:35graingertsetmessages: + msg396558
2021-06-26 22:43:40graingertsetnosy: + gvanrossum
2021-06-15 21:00:19graingertcreate