[3.12] gh-116401: Fix blocking os.fwalk() and shutil.rmtree() on opening a named pipe (GH-116421) (GH-116716)

(cherry picked from commit aa7bcf284f)
This commit is contained in:
Serhiy Storchaka 2024-03-13 12:02:37 +02:00 committed by GitHub
parent 9ef84b46db
commit 9caad1f99b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 113 additions and 8 deletions

View file

@ -676,7 +676,7 @@ def _rmtree_safe_fd(topfd, path, onexc):
continue
if is_dir:
try:
dirfd = os.open(entry.name, os.O_RDONLY, dir_fd=topfd)
dirfd = os.open(entry.name, os.O_RDONLY | os.O_NONBLOCK, dir_fd=topfd)
dirfd_closed = False
except OSError as err:
onexc(os.open, fullname, err)
@ -775,7 +775,7 @@ def rmtree(path, ignore_errors=False, onerror=None, *, onexc=None, dir_fd=None):
onexc(os.lstat, path, err)
return
try:
fd = os.open(path, os.O_RDONLY, dir_fd=dir_fd)
fd = os.open(path, os.O_RDONLY | os.O_NONBLOCK, dir_fd=dir_fd)
fd_closed = False
except Exception as err:
onexc(os.open, path, err)