Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shutil.rmtree() gets stuck on opening named pipe #116401

Closed
Jwata opened this issue Mar 6, 2024 · 0 comments
Closed

shutil.rmtree() gets stuck on opening named pipe #116401

Jwata opened this issue Mar 6, 2024 · 0 comments
Assignees
Labels
3.11 only security fixes 3.12 bugs and security fixes 3.13 bugs and security fixes type-bug An unexpected behavior, bug, or error

Comments

@Jwata
Copy link

Jwata commented Mar 6, 2024

Bug report

Bug description:

When the target is a named pipe, shutil.rmtree() gets stuck on opening it.

# Create a named pipe
import os, tempfile
filename = os.path.join(tempfile.mkdtemp())
filename = os.path.join(tempfile.mkdtemp(), "namedpipe")
os.mkfifo(filename)

# Try to remove it
import shutil
shutil.rmtree(filename) # <- This blocks indefinitely

^CTraceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.11/shutil.py", line 725, in rmtree
    fd = os.open(path, os.O_RDONLY, dir_fd=dir_fd)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyboardInterrupt

This seems to be caused by os.open() with os.O_RDONLY.

fd = os.open(path, os.O_RDONLY, dir_fd=dir_fd)

(This issue seems to exist on the main branch, IIUC)

Currently, it needs to check the file type and use os.remove() if it's a named pipe.
Should this be handled inside shutil.rmtree()?

CPython versions tested on:

3.11

Operating systems tested on:

macOS

Linked PRs

@Jwata Jwata added the type-bug An unexpected behavior, bug, or error label Mar 6, 2024
@serhiy-storchaka serhiy-storchaka self-assigned this Mar 6, 2024
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Mar 6, 2024
@serhiy-storchaka serhiy-storchaka added 3.11 only security fixes 3.12 bugs and security fixes 3.13 bugs and security fixes labels Mar 6, 2024
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Mar 13, 2024
…n opening a named pipe (pythonGH-116421)

(cherry picked from commit aa7bcf2)

Co-authored-by: Serhiy Storchaka <[email protected]>
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Mar 13, 2024
…n opening a named pipe (pythonGH-116421)

(cherry picked from commit aa7bcf2)

Co-authored-by: Serhiy Storchaka <[email protected]>
serhiy-storchaka added a commit that referenced this issue Mar 13, 2024
serhiy-storchaka added a commit that referenced this issue Mar 13, 2024
vstinner pushed a commit to vstinner/cpython that referenced this issue Mar 20, 2024
adorilson pushed a commit to adorilson/cpython that referenced this issue Mar 25, 2024
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes 3.12 bugs and security fixes 3.13 bugs and security fixes type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants