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

OSError: [Errno 39] Directory not empty: 'pixels' when aborting during doc to pixels stage #759

Closed
naglis opened this issue Mar 29, 2024 · 2 comments
Labels
bug Something isn't working stretch goal
Milestone

Comments

@naglis
Copy link
Contributor

naglis commented Mar 29, 2024

Steps to reproduce:

  1. Select an EPUB file in dangerzone 0.6.0 GUI (I've used one with ~1000 pages when in GUI mode to have more time to cancel it).
  2. Click "Convert to Safe Document".
  3. Select "Exit" from the menu while it is still in doc to pixels stage, click "Abort conversions" button in the dialog.
  4. A traceback is printed in the terminal:
Traceback (most recent call last):
  File "/usr/lib/python3.11/weakref.py", line 666, in _exitfunc
    f()
  File "/usr/lib/python3.11/weakref.py", line 590, in __call__
    return info.func(*info.args, **(info.kwargs or {}))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/tempfile.py", line 933, in _cleanup
    cls._rmtree(name, ignore_errors=ignore_errors)
  File "/usr/lib/python3.11/tempfile.py", line 929, in _rmtree
    _shutil.rmtree(name, onerror=onerror)
  File "/usr/lib/python3.11/shutil.py", line 752, in rmtree
    _rmtree_safe_fd(fd, path, onerror)
  File "/usr/lib/python3.11/shutil.py", line 683, in _rmtree_safe_fd
    onerror(os.rmdir, fullname, sys.exc_info())
  File "/usr/lib/python3.11/shutil.py", line 681, in _rmtree_safe_fd
    os.rmdir(entry.name, dir_fd=topfd)
OSError: [Errno 39] Directory not empty: 'pixels'

I am able to reproduce it pretty much every time both via installed package (Arch Linux) and when running from source via dev_scripts. I can also reproduce it if running via dangerzone-cli and then interrupting (Ctrl+C) the process while it is converting pages to pixels.

After dangerzone exits, the pixels subdirectory in the temporary directory created on the host by dangerzone will contain *.{rgb,width,height} files of the pages created after the "Abort conversions" button was pressed.

My speculation on what happens is that tempfile.TemporaryDirectory cleanup is invoked while pixel files are still being produced. The cleanup function uses shutil.rmtree which first deletes the files that exist in the pixels subdirectory and then tries to delete the subdirectory itself, however, since the doc-to-pixel conversion is still running on another thread, it creates new files in the pixels subdirectory in the meantime since rmtree last checked it is empty.

Perhaps some synchronization is needed between the threads after it is clear that dangerzone is exiting to ensure that new files are not being created () in the temporary directory and the TemporaryDirectory cleanup can run cleanly? 🤔

@apyrgio apyrgio added the bug Something isn't working label Apr 1, 2024
@apyrgio apyrgio added this to the 0.7.0 milestone Apr 1, 2024
@apyrgio
Copy link
Contributor

apyrgio commented Apr 1, 2024

Huh, very interesting. We are very close to ditching the temporary directory (see #748) altogether, so this issue will be implicitly solved. Let's keep it open till then.

@apyrgio
Copy link
Contributor

apyrgio commented Oct 29, 2024

The #748 PR is now merged, so we can close this issue as well.

@apyrgio apyrgio closed this as completed Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stretch goal
Projects
None yet
Development

No branches or pull requests

3 participants