Skip to content

[3.14] gh-138720: Make Buffered closed check match flush (GH-138724) - #162459

Merged
cmaloney merged 1 commit into
python:3.14from
cmaloney:backport-db68bfc-3.14
Nov 22, 2026
Merged

cmaloney merged 1 commit into
python:3.14from
cmaloney:backport-db68bfc-3.14

Conversation

@cmaloney

@cmaloney cmaloney commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

In _io__Buffered_flush_impl the macro CHECK_CLOSED is used to check the buffered* is in a good state to be flushed. That differs slightly from buffered_closed.

In some cases, that difference would result in close() thinking the file needed to be flushed and closed while flush() thought the file was already closed.

This could happen during GC and would result in an unraisable exception. (cherry picked from commit db68bfc)


Backporting this finally as without it bots will break on GH-162458

…nGH-138724)

In `_io__Buffered_flush_impl` the macro `CHECK_CLOSED` is used to check
the `buffered*` is in a good state to be flushed. That differs slightly
from `buffered_closed`.

In some cases, that difference would result in `close()` thinking the
file needed to be flushed and closed while `flush()` thought the file
was already closed.

This could happen during GC and would result in an unraisable exception.
(cherry picked from commit db68bfc)

Co-authored-by: Cody Maloney <cmaloney@users.noreply.github.com>
@cmaloney
cmaloney merged commit a182cc8 into python:3.14 Nov 22, 2026
51 checks passed
@cmaloney
cmaloney deleted the backport-db68bfc-3.14 branch November 22, 2026 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant