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

gh-146379: Avoid StreamReader BufferError with active memoryview exports#146380

Open
MadLongTom wants to merge 2 commits intopython:mainfrom
MadLongTom:fix-streamreader-bufferror
Open

gh-146379: Avoid StreamReader BufferError with active memoryview exports#146380
MadLongTom wants to merge 2 commits intopython:mainfrom
MadLongTom:fix-streamreader-bufferror

Conversation

@MadLongTom
Copy link

@MadLongTomMadLongTom commentedMar 24, 2026
edited by bedevere-appbot
Loading

Description

Summary

This PR fixesBufferError inasyncio.StreamReader when a memoryview export exists on the internal buffer andStreamReader performs in-placebytearray mutation.

Problem

CurrentStreamReader logic includes in-place mutations (slice delete / clear). If a memoryview is active,bytearray resizing raises:

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

Changes

  • UpdateStreamReader buffer-consumption paths to avoid in-place resize operations.
  • Use replacement assignment patterns that do not mutate exportedbytearray objects in place.
  • Apply the fix consistently across:
    • read
    • readline
    • readuntil
    • readexactly

Tests

  • Added regression tests for each affected method with an active memoryview on the internal buffer.
  • Added coverage for both normal consume paths and EOF/error paths.
  • Verified tests fail before fix and pass after fix.

Behavioral impact

  • No API change.
  • No semantic change to returned data.
  • Fixes crashes under valid runtime scenarios where memoryview exports exist.

Checklist

  • Added/updated tests
  • Ran relevant test suite successfully
  • Added NEWS entry if required by core team guidance
  • Linked issue in title/body and followed CPython contribution workflow

Fixes#146379

…exportsStreamReader methods (read, readline, readuntil, readexactly) raiseBufferError when a memoryview is held on the internal buffer, becausebuffer mutations (take_bytes, del slice, clear) cannot resize abytearray with active exports.Add _consume_buffer() helper that tries take_bytes() first, thenfalls back to non-mutating object replacement when BufferError israised. Replace all buffer-consumption call sites in StreamReaderto use _consume_buffer().Also fix readline's LimitOverrunError handler which still useddel-slice and .clear() instead of take_bytes().Add 7 regression tests covering all affected methods with an activememoryview on the internal buffer.
@bedevere-app
Copy link

Most changes to Pythonrequire a NEWS entry. Add one using theblurb_it web app or theblurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply theskip news label instead.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@1st11st1Awaiting requested review from 1st11st1 is a code owner

@asvetlovasvetlovAwaiting requested review from asvetlovasvetlov is a code owner

@kumaraditya303kumaraditya303Awaiting requested review from kumaraditya303kumaraditya303 is a code owner

@willingcwillingcAwaiting requested review from willingcwillingc is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

asyncio.StreamReader raises BufferError with active memoryview

1 participant

@MadLongTom

[8]ページ先頭

©2009-2026 Movatter.jp