Fix file descriptor and directory leaks.

Review Request #14805 — Created Feb. 10, 2026 and submitted

Information

Review Board
release-7.1.x

Reviewers

The recent change to add FileAttachment.sha256_checksum as a
cached_property was causing the files to be opened but never closed.
These would pile up, especially while running unit tests, eventually
causing operations to fail due to OS limits on the number of open files
within a process.

While tracking this down, I found a handful of other places throughout
our code where we were either definitely leaking file descriptors, or
had places where an exception could cause a leak. We also never cleaned
up the tests tempdir. This change fixes those up as well.

Ran unit tests.

Summary ID
Fix file descriptor and directory leaks.
The recent change to add `FileAttachment.sha256_checksum` as a `cached_property` was causing the files to be opened but never closed. These would pile up, especially while running unit tests, eventually causing operations to fail due to OS limits on the number of open files within a process. While tracking this down, I found a handful of other places throughout our code where we were either definitely leaking file descriptors, or had places where an exception could cause a leak. We also never cleaned up the tests tempdir. This change fixes those up as well. Testing Done: Ran unit tests.
wrtrmuryqmsrvpmzrwulklzplkmyksyy
Description From Last Updated

Should this be a try/finally?

chipx86chipx86
chipx86
  1. 
      
  2. reviewboard/testing/pytest_fixtures.py (Diff revision 1)
     
     
     
     
    Show all issues

    Should this be a try/finally?

    1. I don't think it needs to be. Unless I guess if pytest itself crashes.

  3. 
      
chipx86
  1. Ship It!
  2. 
      
maubin
  1. I just landed the same change for guess_mimetype, except I wrapped the with differently. Just making a note for when you land and merge.

  2. 
      
david
Review request changed
Status:
Completed
Change Summary:
Pushed to release-7.1.x (45bca7b)