Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Unhandled BrokenPipeError in asyncio.streams #104340

Closed
Labels
@TheTechromancer

Description

@TheTechromancer

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

No one assigned

    Labels

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp