Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Lib/test/test_io/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -2287,6 +2287,10 @@ def test_readinto(self):
self.assertEqual(getattr(pair, method)(data), 5)
self.assertEqual(bytes(data), b"abcde")

# gh-138720: C BufferedRWPair would destruct in a bad order resulting in
# an unraisable exception.
support.gc_collect()

Comment on lines +2290 to +2293
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still necessary?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is way more likely to triggered the issue (fixed behavior) with this change.

Copy link
Contributor Author

@cmaloney cmaloney Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On my dev box (64 bit archlinux) adding the explicit GC takes this from "one in a hundred" -> every time

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK! I couldn't reproduce it myself, but I'll trust the buildbots :)

def test_write(self):
w = self.MockRawIO()
pair = self.tp(self.MockRawIO(), w)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Fix an issue where :class:`io.BufferedWriter` and :class:`io.BufferedRandom`
had different definitions of "closed" for :meth:`~io.IOBase.close` and
:meth:`~io.IOBase.flush` which resulted in an exception when close called
flush but flush thought the file was already closed.
4 changes: 2 additions & 2 deletions Modules/_io/bufferedio.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,8 @@ _io__Buffered_close_impl(buffered *self)
if (!ENTER_BUFFERED(self)) {
return NULL;
}

r = buffered_closed(self);
/* gh-138720: Use IS_CLOSED to match flush CHECK_CLOSED. */
r = IS_CLOSED(self);
if (r < 0)
goto end;
if (r > 0) {
Expand Down
Loading