Title: Abandoned StreamWriter isn't reliably detected · Issue #114914 · python/cpython · GitHub
Open Graph Title: Abandoned StreamWriter isn't reliably detected · Issue #114914 · python/cpython
X Title: Abandoned StreamWriter isn't reliably detected · Issue #114914 · python/cpython
Description: Bug report Bug description: A StreamWriter should be close():d when you are done with it. There is code in the destructor for StreamWriter to detect when this is overlooked and trigger a ResourceWarning. However, the current code often m...
Open Graph Description: Bug report Bug description: A StreamWriter should be close():d when you are done with it. There is code in the destructor for StreamWriter to detect when this is overlooked and trigger a ResourceWa...
X Description: Bug report Bug description: A StreamWriter should be close():d when you are done with it. There is code in the destructor for StreamWriter to detect when this is overlooked and trigger a ResourceWa...
Opengraph URL: https://github.com/python/cpython/issues/114914
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Abandoned StreamWriter isn't reliably detected","articleBody":"# Bug report\n\n### Bug description:\n\nA StreamWriter should be `close()`:d when you are done with it. There is code in the destructor for StreamWriter to detect when this is overlooked and trigger a `ResourceWarning`. However, the current code often maintains a strong reference to the writer, preventing it from being garbage collected and hence no warning.\n\nTest case:\n\n```python\n#!/usr/bin/python3\n\nimport asyncio\nimport gc\nimport socket\n\nasync def handle_echo(reader, writer):\n addr = writer.get_extra_info('peername')\n print(f\"Connection from {addr!r}\")\n # Forgetting to close the writer\n #writer.close()\n #await writer.wait_closed()\n\nasync def main():\n server = await asyncio.start_server(\n handle_echo, '127.0.0.1', 8888)\n\n addrs = ', '.join(str(sock.getsockname()) for sock in server.sockets)\n print(f'Serving on {addrs}')\n\n client = socket.create_connection(('127.0.0.1', 8888))\n client.send(b'a' * 64 * 1024)\n\n async with server:\n for i in range(25):\n await asyncio.sleep(0.1)\n gc.collect()\n print('Exiting')\n\n print('Done serving')\n\n client.close()\n\nasyncio.run(main())\n```\n\nTest case locks up waiting for the client connection, when instead I would expect a `ResourceWarning` and everything exiting nicely.\n\n### CPython versions tested on:\n\n3.12, CPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-115661\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/CendioOssman","@type":"Person","name":"CendioOssman"},"datePublished":"2024-02-02T15:03:50.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/114914/cpython/issues/114914"}
| 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:e7a691a6-291a-4f35-c0ae-045c1a30ec3d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D38A:374780:84487E:B30EBA:696AB4EE |
| html-safe-nonce | e9bd30b4ec748c357568b275e87c532e56aaac655402f4a7397afaf8791e3cbf |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMzhBOjM3NDc4MDo4NDQ4N0U6QjMwRUJBOjY5NkFCNEVFIiwidmlzaXRvcl9pZCI6IjU1MDU2ODMzNzY5NTkwNDI3OTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 2677e9455a2839829f76351107a4027833e18294652c46bdca8187b78f160dbe |
| hovercard-subject-tag | issue:2115137183 |
| 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/114914/issue_layout |
| twitter:image | https://opengraph.githubassets.com/692507d2269dc848eda20a7a5ec79209018f67667b2324e0127d5213d7dd17cb/python/cpython/issues/114914 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/692507d2269dc848eda20a7a5ec79209018f67667b2324e0127d5213d7dd17cb/python/cpython/issues/114914 |
| og:image:alt | Bug report Bug description: A StreamWriter should be close():d when you are done with it. There is code in the destructor for StreamWriter to detect when this is overlooked and trigger a ResourceWa... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | CendioOssman |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4fa1799b6a53c2d30c950d74230781bef9e7f61138c72c7727e4b83f0743752b |
| 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 | 41f276818bd204c4a30a0281fb3c576298d9474c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width