Title: Unclosed socket in urllib when ftp request times out after connect · Issue #140691 · python/cpython · GitHub
Open Graph Title: Unclosed socket in urllib when ftp request times out after connect · Issue #140691 · python/cpython
X Title: Unclosed socket in urllib when ftp request times out after connect · Issue #140691 · python/cpython
Description: Bug report Bug description: Spotted in the log of "Log from "buildbot/ARM64 macOS 3.x"; this doesn't fix the ftp test but when the operation times out in the test CPython should close the socket This seems to be originating here: cpython...
Open Graph Description: Bug report Bug description: Spotted in the log of "Log from "buildbot/ARM64 macOS 3.x"; this doesn't fix the ftp test but when the operation times out in the test CPython should close the socket Th...
X Description: Bug report Bug description: Spotted in the log of "Log from "buildbot/ARM64 macOS 3.x"; this doesn't fix the ftp test but when the operation times out in the test CPython should ...
Opengraph URL: https://github.com/python/cpython/issues/140691
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Unclosed socket in urllib when ftp request times out after connect","articleBody":"# Bug report\n\n### Bug description:\n\nSpotted in the log of \"Log from \"buildbot/ARM64 macOS 3.x\"; this doesn't fix the ftp test but when the operation times out in the test CPython should close the socket\n\nThis seems to be originating here:\nhttps://github.com/python/cpython/blob/f5394c257ce4118394fe5ff561a2b0ad238a8d65/Lib/urllib/request.py#L1539-L1556\n\nIn particular, `fw = self.connect_ftp` succeeds which means `fw` contains an open connection but `fp, retrlen = fw.retrfile(file, type)` fails and the `except` doesn't result in a `fw.close()`.\n\n\n\u003cdetails>\u003csummary>Log from \"buildbot/ARM64 macOS 3.x\"\u003c/summary>\n\u003cp>\n\n```python\nException ignored while finalizing socket \u003csocket.socket fd=6, family=2, type=1, proto=6, laddr=('192.168.0.101', 57993), raddr=('68.183.26.59', 21)>:\nTraceback (most recent call last):\n File \"/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/urllib/request.py\", line 1546, in ftp_open\n fp, retrlen = fw.retrfile(file, type)\n ~~~~~~~~~~~^^^^^^^^^^^^\n File \"/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/urllib/request.py\", line 1826, in retrfile\n conn, retrlen = self.ftp.ntransfercmd(cmd)\n ~~~~~~~~~~~~~~~~~~~~~^^^^^\n File \"/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/ftplib.py\", line 354, in ntransfercmd\n conn = socket.create_connection((host, port), self.timeout,\n source_address=self.source_address)\n File \"/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/socket.py\", line 879, in create_connection\n raise exceptions[0]\n File \"/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/socket.py\", line 864, in create_connection\n sock.connect(sa)\n ~~~~~~~~~~~~^^^^\nTimeoutError: [Errno 60] Operation timed out\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/test/test_urllib2net.py\", line 20, in _retry_thrice\n return func(*args, **kwargs)\n File \"/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/urllib/request.py\", line 187, in urlopen\n return opener.open(url, data, timeout)\n ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^\n File \"/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/urllib/request.py\", line 487, in open\n response = self._open(req, data)\n File \"/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/urllib/request.py\", line 504, in _open\n result = self._call_chain(self.handle_open, protocol, protocol +\n '_open', req)\n File \"/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/urllib/request.py\", line 464, in _call_chain\n result = func(*args)\n File \"/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/urllib/request.py\", line 1556, in ftp_open\n raise URLError(f\"ftp error: {exp}\") from exp\nurllib.error.URLError: \u003curlopen error ftp error: [Errno 60] Operation timed out>\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/test/test_urllib2net.py\", line 22, in _retry_thrice\n last_exc = e\n ^^^^^^^^\nResourceWarning: unclosed \u003csocket.socket fd=6, family=2, type=1, proto=6, laddr=('192.168.0.101', 57993), raddr=('68.183.26.59', 21)>\nWarning -- Unraisable exception\nException ignored while finalizing socket \u003csocket.socket fd=8, family=2, type=1, proto=6, laddr=('192.168.0.101', 58055), raddr=('68.183.26.59', 21)>:\nTraceback (most recent call last):\n File \"/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/urllib/request.py\", line 1546, in ftp_open\n fp, retrlen = fw.retrfile(file, type)\n ~~~~~~~~~~~^^^^^^^^^^^^\n File \"/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/urllib/request.py\", line 1826, in retrfile\n conn, retrlen = self.ftp.ntransfercmd(cmd)\n ~~~~~~~~~~~~~~~~~~~~~^^^^^\n File \"/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/ftplib.py\", line 354, in ntransfercmd\n conn = socket.create_connection((host, port), self.timeout,\n source_address=self.source_address)\n File \"/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/socket.py\", line 879, in create_connection\n raise exceptions[0]\n File \"/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/socket.py\", line 864, in create_connection\n sock.connect(sa)\n ~~~~~~~~~~~~^^^^\nTimeoutError: [Errno 60] Operation timed out\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/test/test_urllib2net.py\", line 20, in _retry_thrice\n return func(*args, **kwargs)\n File \"/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/urllib/request.py\", line 187, in urlopen\n return opener.open(url, data, timeout)\n ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^\n File \"/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/urllib/request.py\", line 487, in open\n response = self._open(req, data)\n File \"/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/urllib/request.py\", line 504, in _open\n result = self._call_chain(self.handle_open, protocol, protocol +\n '_open', req)\n File \"/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/urllib/request.py\", line 464, in _call_chain\n result = func(*args)\n File \"/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/urllib/request.py\", line 1556, in ftp_open\n raise URLError(f\"ftp error: {exp}\") from exp\nurllib.error.URLError: \u003curlopen error ftp error: [Errno 60] Operation timed out>\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"/Users/buildbot/buildarea/3.x.pablogsal-macos-m1.macos-with-brew/build/Lib/test/test_urllib2net.py\", line 22, in _retry_thrice\n last_exc = e\n ^^^^^^^^\nResourceWarning: unclosed \u003csocket.socket fd=8, family=2, type=1, proto=6, laddr=('192.168.0.101', 58055), raddr=('68.183.26.59', 21)>\n\n```\n\u003c/p>\n\u003c/details>\n\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nmacOS\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-140694\n* gh-140835\n* gh-141555\n* gh-141657\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/cmaloney","@type":"Person","name":"cmaloney"},"datePublished":"2025-10-27T23:39:14Z","url":"https://github.com/python/cpython/issues/140691"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:7c036776-4290-2924-b868-12199d30981f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B6D2:14EB6E:18B19A3:20721BC:6B02096C |
| html-safe-nonce | a0ca3910aa67582605fcf858f71208bd414d6eddfa529c23009f509e23a98284 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNkQyOjE0RUI2RToxOEIxOUEzOjIwNzIxQkM6NkIwMjA5NkMiLCJ2aXNpdG9yX2lkIjoiOTE1MjI5MDEzMjMzMjc3NTc4OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f53d9afa0787a1e9ab0eeb0aacf566ab8353b73966735c3f111b3be3699cfd94 |
| hovercard-subject-tag | issue:3559101446 |
| 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/140691/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4ac417452466749ae0d84be760da4eaae34eb16120c54735e9f646a896f85d92/python/cpython/issues/140691 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4ac417452466749ae0d84be760da4eaae34eb16120c54735e9f646a896f85d92/python/cpython/issues/140691 |
| og:image:alt | Bug report Bug description: Spotted in the log of "Log from "buildbot/ARM64 macOS 3.x"; this doesn't fix the ftp test but when the operation times out in the test CPython should close the socket Th... |
| 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 | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width