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: github.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:293c9672-af08-cc3e-cf99-b825229253a0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 81E0:1D5BA4:94E494:CFF2F0:696E639A |
| html-safe-nonce | fad81621219237479b24f31c2322b66e82fc214272dc6ed03034f3710bba3d72 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MUUwOjFENUJBNDo5NEU0OTQ6Q0ZGMkYwOjY5NkU2MzlBIiwidmlzaXRvcl9pZCI6IjQ2ODUxNTcxODY3NTU1MTkzODYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 99288bf9abe1542883cc5f8a7b50dc7db41b813afe0c8434b43736662afc6266 |
| 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 | 99a4a74f92e7618f6e15b4dbb9f4470c8d31701a90d89c21ff31970528b7f0c3 |
| 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 | ef0d97829e997c64864f25a29b00067f5dc3a4c4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width