Skip to content

Fix Resource Leak in ArtResizer with test cases #5746

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

brahilumich
Copy link

Fix Resource Leak in ArtResizer : Fixes #5689

Hello,
This is my first time submitting a pull request so any feedback would be much appreciated.

I was attempting to make sure that art resizer does not keep file handles open. In artresizer.py I manual remove opened files to ensure there no leftover nor corrupt file in path_out.

I created a test called test_artresizer_resources.py. For testing, I used the pillow library which was added to pyproject.toml. The test suite works by counting the number of files before and after the operation while ensuring the proper file is returned. This test file was failing before I added my changes but was resolved when the changes were made. I ran my code against the entire pytest suite which seemed to work as intended.

Add Pillow = "*" in [tool.poetry.group.test.dependencies]
Create a test to check for resource leaks in artresizer
Fix problem associated with beetbox#5689 and test_artresizer_resources.py
Copy link

Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry.

@wisp3rwind
Copy link
Member

Please see our guide on how to set up a development environment and installing (test) dependencies, instead of working around it like you do here (by moving things around in pyproject.toml, and by manually messing around with sys.path).

There are definitely issues with the tests:

  • They don't hook into the usual setUp + tearDown mechanisms, but use another style of setup_ and teardown_ methods that I don't remember seeing before. A quick search suggests that this is https://docs.pytest.org/en/6.2.x/xunit_setup.html#method-and-function-level-setup-teardown but I suspect that that really stems from a different time (around 2010?). Please use the same style as every other test in the codebase.
  • Creating a temporary directory with a fixed name in tempfile.gettempdir() is definitely not robust. We have temp directory helpers in the TestHelper class you're already inheriting from.
  • I also don't see how your changes affect the test cases: If the dummy image is in fact a valid jpeg, you should never be hitting the error case that you're modifying.
  • ...

Also, I don't think this fixes #5689: Checking for stale files after Pillow/Magick returns an error seems sensible, but there's no indication in #5689 that that's what's happend. Fixing that issue would certainly require figuring out what happens in the first place. A first step should be asking for more details over at the issue. A verbose log of the actions leading up to the issue might be interesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ArtResizer holds file handles for every album art created when using the convert plugin
2 participants