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-138720: Make Buffered closed check match flush#138724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
encukou merged 5 commits intopython:mainfromcmaloney:bufferedrwpair_gc
Sep 18, 2025

Conversation

@cmaloney
Copy link
Contributor

@cmaloneycmaloney commentedSep 10, 2025
edited
Loading

In_io__Buffered_flush_impl the macroCHECK_CLOSED is used to check thebuffered* is in a good state to be flushed. That differs slightly frombuffered_closed.

In some cases, that difference would result inclose() (_io__Buffered_close_impl) thinking the file needed to be flushed and closed whileflush() thought the file was already closed.

This could happen during GC and would result in an unraisable exception.

In `_io__Buffered_flush_impl` the macro `CHECK_CLOSED` is used to checkthe `buffered*` is in a good state to be flushed. That differs slightlyfrom `buffered_closed`.In some cases, that difference would result in `close()` thinking thefile needed to be flushed and closed while `flush()` thought the filewas already closed.This could happen during GC and would result in an unraisable exception.
@cmaloney
Copy link
ContributorAuthor

cmaloney commentedSep 16, 2025
edited
Loading

For this, I also looked at resolving two other ways:

  1. Updating.closed member: This makes it so.close() isn't called (and therefore.flush()). A lot more tests break with that change, this to me is more minimal fix; BufferedRWPair is not often used (and was thought of being removed once).
  2. Figure out why the GC isn't clearing out in a clean order and resolve: Again fairly intricate to do with a lot more potential unintended consequences.

@encukou
Copy link
Member

!buildbot PPC64LE.Fedora.Stable.LTO

@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by@encukou for commit60fe309 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F138724%2Fmerge

The command will test the builders whose names match following regular expression:PPC64LE.Fedora.Stable.LTO

The builders matched are:

  • PPC64LE Fedora Stable LTO PR
  • PPC64LE Fedora Stable LTO + PGO PR

Copy link
Member

@encukouencukou left a comment

Choose a reason for hiding this comment

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

Thank you! This looks like a correct change.

Comment on lines +2290 to +2293
# gh-138720: C BufferedRWPair would destruct in a bad order resulting in
# an unraisable exception.
support.gc_collect()

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
ContributorAuthor

@cmaloneycmaloneySep 17, 2025
edited
Loading

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

encukou reacted with thumbs up emoji
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 :)

@encukouencukou merged commitdb68bfc intopython:mainSep 18, 2025
51 checks passed
@vstinner
Copy link
Member

Should we backport this bugfix?

@encukou
Copy link
Member

Can you reproduce it on previous versions? If so, please backport :)

@vstinner
Copy link
Member

Can you reproduce it on previous versions? If so, please backport :)

Oh. I'm unable to reproduce the issue on 3.14.

@cmaloneycmaloney deleted the bufferedrwpair_gc branchSeptember 18, 2025 19:26
@cmaloney
Copy link
ContributorAuthor

The code has been the same since the C I/O implementation was added; unless/until someone has an issue on older versions I wouldn't backport.

vstinner reacted with thumbs up emoji

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

Reviewers

@vstinnervstinnervstinner left review comments

@encukouencukouencukou approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@cmaloney@encukou@bedevere-bot@vstinner

[8]ページ先頭

©2009-2025 Movatter.jp