Skip to content

HDF5: Close operations also upon failure#1866

Open
franzpoeschel wants to merge 2 commits intoopenPMD:devfrom
franzpoeschel:hdf5-fix-nonexistent-attribute-read
Open

HDF5: Close operations also upon failure#1866
franzpoeschel wants to merge 2 commits intoopenPMD:devfrom
franzpoeschel:hdf5-fix-nonexistent-attribute-read

Conversation

@franzpoeschel
Copy link
Copy Markdown
Contributor

@franzpoeschel franzpoeschel commented Mar 26, 2026

Basically our entire HDF5 implementation is a resource leak in the error case. This PR uses RAII to implement a deferred cleanup operation (similar to how Go handles resource freeing)

TODO:

  • Add a test for this: Do some kind of nonexistent attribute read, the HDF5 handle will stay open, HDF5 will fail upon writing to the Series for a second time
  • fix this for the entire remaining HDF5 implementation......
  • Verify the vibe-coded commit

@franzpoeschel franzpoeschel added this to the 0.17.1 milestone Mar 26, 2026
@franzpoeschel franzpoeschel marked this pull request as ready for review March 26, 2026 12:26
@franzpoeschel franzpoeschel force-pushed the hdf5-fix-nonexistent-attribute-read branch from 08a93f1 to dfb7d8c Compare March 27, 2026 10:20
Apply the defer pattern (introduced in readAttribute fix) to ensure HDF5
resources are properly closed when exceptions occur in writeAttribute,
readDataset, listPaths, listDatasets, listAttributes, and deleteAttribute.

The defer pattern uses auxiliary::defer to register cleanup callbacks that
run automatically when the function exits, ensuring resources are released
even when errors occur mid-function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant