Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Bug report
Kind of a weird one here, been running into it a for a while but just recently figured out how to reproduce it reliably.
Basically, if an async process is killed while a large amount of data remains to be written to its stdin, it fails to throw aConnectionResetError and instead experiences aBrokenPipeError inside the_drain_helper() method. Because the exception happens inside an internal task, it evades handling by the user.
Traceback (mostrecentcalllast):File"/brokenpipeerror_bug.py",line28,inmainawaitproc.stdin.drain()File"/usr/lib/python3.10/asyncio/streams.py",line371,indrainawaitself._protocol._drain_helper()File"/usr/lib/python3.10/asyncio/streams.py",line173,in_drain_helperawaitwaiterBrokenPipeError
Minimal reproducible example:
importasyncioimporttracebackasyncdefmain():proc=awaitasyncio.create_subprocess_exec("sleep","999",stdin=asyncio.subprocess.PIPE)try:for_inrange(10000):# NOTE: only triggers if this is a high numberi=b"www.blacklanternsecurity.com\n"proc.stdin.write(i)proc.kill()awaitproc.stdin.drain()# This triggers errorexceptBrokenPipeError:print(f"Handled error:{traceback.format_exc()}")asyncio.run(main())
$ python brokenpipeerror_bug.py Handled error: Traceback (most recent call last): File"/brokenpipeerror_bug.py", line 28,in main awaitproc.stdin.drain() File"/usr/lib/python3.10/asyncio/streams.py", line 371,in drain awaitself._protocol._drain_helper() File"/usr/lib/python3.10/asyncio/streams.py", line 173,in _drain_helper await waiterBrokenPipeErrorFuture exception was never retrievedfuture:<Future finished exception=BrokenPipeError()>Traceback (most recent call last): File"/brokenpipeerror_bug.py", line 28,in main awaitproc.stdin.drain() File"/usr/lib/python3.10/asyncio/streams.py", line 371,in drain awaitself._protocol._drain_helper() File"/usr/lib/python3.10/asyncio/streams.py", line 173,in _drain_helper await waiterBrokenPipeError
Tested on CPython 3.10.10 on Arch Linux, x86_64
Linked PRs
Metadata
Metadata
Assignees
Projects
Status
Done