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
leak if we use the "try dict[key] / except KeyError" idiom with h5py attrs #2350
Comments
Thank-you! Is it possible for you to share a sample file to run that script on? Or even better, a bit of Python code that will create a file like that? I'm a bit puzzled because the line you point to as allocating the memory is in the dataset read code, not the attributes where you're catching KeyError. Lines 756 to 758 in 89374b7
|
knee-jerk guess: when attribute access fails we fail to decref the dataset (or something that holds a reference to it). I suspect the thing to look at is to chase through Lines 79 to 81 in 4c01efa
KeyError .
A second knee-jerk guess: the stack-trace is keeping things alive. |
What I'm seeing is none of the objects allocated while reading the file are freed once the bug is triggered. |
Here's a sample ODIM HDF5 file someone kindly uploaded to github: https://github.com/adokter/ODIM-hdf5-test/blob/master/pvol/bejab_pvol_20151009T0000Z.h5 |
For me (also on Fedora 39) your script seems to work correctly, with no leak 😕
|
Experimenting a bit more: I do see the leak with the Fedora build of h5py:
But if I use pip to install h5py 3.10.0 from a wheel on PyPI, it doesn't leak:
There are a few patches in Fedora, but none of them look obviously relevant. Fedora's packages are built against a newer Cython, but an older NumPy and HDF5, so I guess one of those version differences is probably the key. |
I can not reproduce this with my all-the-defaults environment:
nor with the system packages from Arch.
Thank you for an A+ reproducer script + data! |
h5py never releases data if we use the 'try dict[key] / except KeyError' idiom with h5py attrs.
On fc39: python3-3.12.0, hdf5-1.12.1, python3-h5py-3.10.0 (leaks)
On fc36: python3-3.10.11, hdf5-1.12.1, python3-h5py-3.6.0 (no leak)
Output from attached script on Fedora 39 (leaks)
See in particular the second
dataset.py
tracemalloc line with 10x the count and memory expected.Output from attached script on Fedora 36 (no leak)
Script
The text was updated successfully, but these errors were encountered: