Skip to content

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

Closed
@Jwata

Description

@Jwata

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

Metadata

Metadata

Labels

3.11only security fixes3.12only security fixes3.13bugs and security fixestype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions