python / python/cpython

TemporaryDirectory ignore_cleanup_errors flag is not robustic

Abierto
#135,812 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

stdlib type-bug
Lenguaje dominante
Python
Estrellas
77.2k
Forks
35.9k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

Bug report

Bug description:

When using ignore_cleanup_errors flag in TemporaryDirectory context manager, there's a path that will raise an issue.

In the onerror function that's being called when error in rmtree function:
If the first error is FileNotFound, pass
If it's everything else, check the ignore_errors flag, and raise if set to False
if the error was PermissionsError first try to change the permissions (the call to _resetperms , and then try to remove the files again. But the the call to resetparams is in an outer try, which is a lot weaker, and catching only the FileNotFoundError . But in our case, this very call raised PermissionError (yet again). It was not caught and raised back to our code.

Internal logs

2025-06-16 08:07:41 - ERROR - failed to solve strawman_local_enumeration: [Errno 1] Operation not permitted: '/tmp/tmpsrelpq9p/__pycache__'
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.11.8/x64/lib/python3.11/shutil.py", line 701, in _rmtree_safe_fd
    os.unlink(entry.name, dir_fd=topfd)
PermissionError: [Errno 13] Permission denied: 'main.cpython-310.pyc'


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/runner/work/CTF/CTF/src/solvers/solvers/solve_remote/solve_remote.py", line 212, in solve_remote_single
    return solve_challenge_on_local_solver(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

...

 File "/opt/hostedtoolcache/Python/3.11.8/x64/lib/python3.11/tempfile.py", line 287, in _resetperms
    _dont_follow_symlinks(_os.chmod, path, 0o700)
  File "/opt/hostedtoolcache/Python/3.11.8/x64/lib/python3.11/tempfile.py", line 278, in _dont_follow_symlinks
    func(path, *args)
PermissionError: [Errno 1] Operation not permitted: '/tmp/tmpsrelpq9p/__pycache__'
CPython versions tested on:

3.11

Operating systems tested on:

macOS, Linux

Linked PRs
  • gh-150696

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con _resetperms de tempfile.py y la ruta de limpieza de TemporaryDirectory, y compárala después con el manejo de onerror de shutil.rmtree. Reproduce el caso de PermissionError en Python 3.11 en macOS o Linux y añade una prueba de regresión que demuestre que ignore_cleanup_errors evita que el fallo de limpieza se propague.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
operating-systems
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.