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
|