Title: GC of unclosed io.BuffererdRWPair after `.readinto` results in unraisable exception · Issue #138720 · python/cpython · GitHub
Open Graph Title: GC of unclosed io.BuffererdRWPair after `.readinto` results in unraisable exception · Issue #138720 · python/cpython
X Title: GC of unclosed io.BuffererdRWPair after `.readinto` results in unraisable exception · Issue #138720 · python/cpython
Description: Bug report Bug description: In BufferedRWPairTest.test_readinto a BufferedRWPair is created but not explicitly closed which results in it being Garbage Collected (GC). During GC the destruction order often results in an unraisable except...
Open Graph Description: Bug report Bug description: In BufferedRWPairTest.test_readinto a BufferedRWPair is created but not explicitly closed which results in it being Garbage Collected (GC). During GC the destruction ord...
X Description: Bug report Bug description: In BufferedRWPairTest.test_readinto a BufferedRWPair is created but not explicitly closed which results in it being Garbage Collected (GC). During GC the destruction ord...
Opengraph URL: https://github.com/python/cpython/issues/138720
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"GC of unclosed io.BuffererdRWPair after `.readinto` results in unraisable exception","articleBody":"# Bug report\n\n### Bug description:\n\nIn `BufferedRWPairTest.test_readinto` a `BufferedRWPair` is created but not explicitly closed which results in it being Garbage Collected (GC). During GC the destruction order often results in an unraisable exception. This can be reliably reproduced by modifying the test to end with `support.gc_collect()`. The BufferedRWPair should cleanup reliably in this case.\n\nhttps://github.com/python/cpython/blob/6bc65c30ff1fd0b581a2c93416496fc720bc442c/Lib/test/test_io/test_general.py#L2281-L2288\n\n\n```python\nWarning -- Unraisable exception\nException ignored while finalizing file \u003c_io.BufferedRWPair object at 0x7fd9d7577950\u003e:\nTraceback (most recent call last):\n File \"\u003ccheckout_dir\u003e/cpython/Lib/test/support/__init__.py\", line 837, in gc_collect\n gc.collect()\n ~~~~~~~~~~^^\nValueError: flush of closed file\nWarning -- Unraisable exception\nException ignored while finalizing file \u003c_io.BufferedWriter\u003e:\nTraceback (most recent call last):\n File \"\u003ccheckout_dir\u003e/cpython/Lib/test/support/__init__.py\", line 837, in gc_collect\n gc.collect()\n ~~~~~~~~~~^^\nValueError: flush of closed file\n```\n\nFound while working on GH-138475\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-138724\n* gh-138771\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/cmaloney","@type":"Person","name":"cmaloney"},"datePublished":"2025-09-09T21:21:18.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/138720/cpython/issues/138720"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b8d5c71d-ace7-0fa0-c04e-eee2566be72d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D010:199219:1CA97E5:25CEFC0:6A51E13C |
| html-safe-nonce | fc64db9779d0707bb74b626da30db1f742ac98a67132d8a1f4efb817d7be557c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMDEwOjE5OTIxOToxQ0E5N0U1OjI1Q0VGQzA6NkE1MUUxM0MiLCJ2aXNpdG9yX2lkIjoiNDczNDY5MzAxNTk4NTE4NTA4NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b31ae1ea3fe8c6c32ba7b45dd608f4136842c3c77c971aec91da755e5f6eabba |
| hovercard-subject-tag | issue:3399997139 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/138720/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bb05b967088d5a6a1145d9738e4dbaf8ab200eeaf823be7deb85e55f843f4784/python/cpython/issues/138720 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bb05b967088d5a6a1145d9738e4dbaf8ab200eeaf823be7deb85e55f843f4784/python/cpython/issues/138720 |
| og:image:alt | Bug report Bug description: In BufferedRWPairTest.test_readinto a BufferedRWPair is created but not explicitly closed which results in it being Garbage Collected (GC). During GC the destruction ord... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | cmaloney |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width