Title: pathlib.Path.copy() hangs on FIFO pipes and loops infinitely on /dev/zero · Issue #143968 · python/cpython · GitHub
Open Graph Title: pathlib.Path.copy() hangs on FIFO pipes and loops infinitely on /dev/zero · Issue #143968 · python/cpython
X Title: pathlib.Path.copy() hangs on FIFO pipes and loops infinitely on /dev/zero · Issue #143968 · python/cpython
Description: Bug Description pathlib.Path.copy() (introduced recently) attempts to open and copy any file type that is not a directory or a symlink. This causes severe issues with special files: FIFOs (Named Pipes): Opening a FIFO for reading blocks ...
Open Graph Description: Bug Description pathlib.Path.copy() (introduced recently) attempts to open and copy any file type that is not a directory or a symlink. This causes severe issues with special files: FIFOs (Named Pi...
X Description: Bug Description pathlib.Path.copy() (introduced recently) attempts to open and copy any file type that is not a directory or a symlink. This causes severe issues with special files: FIFOs (Named Pi...
Opengraph URL: https://github.com/python/cpython/issues/143968
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"pathlib.Path.copy() hangs on FIFO pipes and loops infinitely on /dev/zero","articleBody":"# Bug Description\n`pathlib.Path.copy()` (introduced recently) attempts to open and copy any file type that is not a directory or a symlink. This causes severe issues with special files:\n1. **FIFOs (Named Pipes)**: Opening a FIFO for reading blocks indefinitely if there is no writer, causing the process to hang using CPU.\n2. **Infinite Sources**: Reading from character devices like `/dev/zero` results in an infinite loop, potentially filling up the disk or freezing the application.\n\n`shutil.copyfile` correctly handles this by raising `SpecialFileError` (or similar) when encountering these files. `pathlib` should behave similarly or at least safely.\n\n# Reproduction\n```python\nimport os\nimport pathlib\nimport signal\nimport time\n\nfifo_name = \"test_fifo_hang\"\nif os.path.exists(fifo_name):\n os.remove(fifo_name)\nos.mkfifo(fifo_name)\n\n# This will hang indefinitely\nprint(\"Attempting to copy FIFO...\")\np = pathlib.Path(fifo_name)\ntry:\n p.copy(\"test_fifo_dest\") \nexcept Exception as e:\n print(f\"Caught: {e}\")\nelse:\n print(\"Copy finished (unexpected!)\")\nfinally:\n os.remove(fifo_name)\n```\n\n# Expected Behavior\nThe operation should fail immediately with `io.UnsupportedOperation` or `shutil.SameFileError` / `SpecialFileError` instead of hanging or looping.\n\n# Proposed Solution\nCheck `is_file()` in `pathlib.Path.copy` (specifically `_copy_from`) to ensure we only copy regular files.\n\nI have a PR ready for this.\n\n### CPython versions tested on:\n\n3.14\n\n### Operating systems tested on:\n\nmacOS\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-143966\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/tonghuaroot","@type":"Person","name":"tonghuaroot"},"datePublished":"2026-01-17T15:44:50.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/143968/cpython/issues/143968"}
| 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:a1dc3691-adf0-b014-47d3-cf4670d9d032 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DC36:28DD58:36DA9F4:48AA227:696DCC7D |
| html-safe-nonce | 8adf913c57db64bcbde1c0ef2506e94608ad3b48a0d4abb337eb0ac69638f37e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQzM2OjI4REQ1ODozNkRBOUY0OjQ4QUEyMjc6Njk2RENDN0QiLCJ2aXNpdG9yX2lkIjoiMTg5MjE5NTAxMTM1MjQ0ODEyNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e01161c0210242be5e81fe7c5e479d635a52d4d116c681f0b906ca1ea2f72fc9 |
| hovercard-subject-tag | issue:3825434044 |
| 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/143968/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5663f6ea28c8de0b5e4e3611356893aa2bc1f57fce476877de3ac3de2a09b217/python/cpython/issues/143968 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5663f6ea28c8de0b5e4e3611356893aa2bc1f57fce476877de3ac3de2a09b217/python/cpython/issues/143968 |
| og:image:alt | Bug Description pathlib.Path.copy() (introduced recently) attempts to open and copy any file type that is not a directory or a symlink. This causes severe issues with special files: FIFOs (Named Pi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | tonghuaroot |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4922b452d03cd8dbce479d866a11bc25b59ef6ee2da23aa9b0ddefa6bd4d0064 |
| 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 | 7e5ae23c70136152637ceee8d6faceb35596ec46 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width