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

asyncio.StreamReader raises BufferError with active memoryview #146379

Labels
pendingThe issue will be closed if no feedback is providedstdlibStandard Library Python modules in the Lib/ directorytopic-asynciotype-bugAn unexpected behavior, bug, or error
@MadLongTom

Description

@MadLongTom

Bug report

Bug description:

Summary

WhenStreamReader has an active memoryview export of its internal buffer, methods that mutate the buffer in place can raise:

BufferError: Existing exports of data: object cannot be re-sized

This appears in real workloads with async database drivers, but the root cause is inStreamReader buffer mutation behavior.

Steps to reproduce

importasyncioasyncdefmain():r=asyncio.StreamReader()r.feed_data(b"AABBCCDD")# Simulate a consumer that keeps a memoryview alivemv=memoryview(r._buffer)# Triggers BufferError in current implementationawaitr.readexactly(4)mv.release()asyncio.run(main())

Expected behavior

readexactly(4) should returnb"AABB" without raisingBufferError.

Actual behavior

BufferError: Existing exports of data: object cannot be re-sized

Why this happens

SomeStreamReader paths mutatebytearray in place, for example slice deletion and clear operations. In-place resize is not allowed while a memoryview export exists.

Affected methods

  • read
  • readline
  • readuntil
  • readexactly

Environment

  • Python: 3.13.x, 3.14.x (also reproducible in local tests with newer builds)
  • OS: macOS (also observed in Linux server workloads)
  • Third-party context where this is frequently hit: async DB drivers using memoryview over packet buffers

Possible fix direction

Replace in-place buffer mutations with non-mutating replacement assignments, for example:

  • replace slice delete with reassignment to remaining bytes
  • replace clear with assigning a new empty bytearray

If useful, I can open a PR with tests covering the regression paths.

CPython versions tested on:

3.13

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    pendingThe issue will be closed if no feedback is providedstdlibStandard Library Python modules in the Lib/ directorytopic-asynciotype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2026 Movatter.jp