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

remove H5close call, introduce specific hdf5 object H5xclose calls #397

Merged
merged 1 commit into from
Apr 8, 2019
Merged

remove H5close call, introduce specific hdf5 object H5xclose calls #397

merged 1 commit into from
Apr 8, 2019

Conversation

hinxx
Copy link
Contributor

@hinxx hinxx commented Apr 7, 2019

The initial fix for memory leaks that added a call to H5close() was not proper. It caused IOC crashes if two HDF5 plugin instances were used (#390 (comment)).

This set of changes removes the call to H5close() and adds localized resource freeing that should result in no memory leaks.

I added comments to the code paths that I've seen taken (// HK OK). Some other cases I did not test or verify (i.e. error branches) and for those the comment reads // HK test.

Someone needs to go over my changes and verify the correctness.

@hinxx
Copy link
Contributor Author

hinxx commented Apr 7, 2019

I have been running a simdetector IOC with two instances of HDF5 plugins for a while and have not noticed any memory leaks with these changes.

An example of the test run:

hinxx@obzen ~/bde/R3.15.5/simioc-master/tests $ bash test-hdf5-memlkeak.sh 
Old : SIM1:cam1:AcquireTime          0.05
New : SIM1:cam1:AcquireTime          0.05
Old : SIM1:cam1:NumImages            1
New : SIM1:cam1:NumImages            1
Old : SIM1:HDF1:FilePath \003
New : SIM1:HDF1:FilePath /tmp
Old : SIM1:HDF1:FileName \003
New : SIM1:HDF1:FileName 1test_hdf5
Old : SIM1:HDF1:AutoIncrement        No
New : SIM1:HDF1:AutoIncrement        Yes
Old : SIM1:HDF1:FileTemplate \003
New : SIM1:HDF1:FileTemplate %s%s_%d.h5
Old : SIM1:HDF1:AutoSave             No
New : SIM1:HDF1:AutoSave             Yes
Old : SIM1:HDF1:StorePerform         Yes
New : SIM1:HDF1:StorePerform         Yes
Old : SIM1:HDF1:StoreAttr            Yes
New : SIM1:HDF1:StoreAttr            Yes
Old : SIM1:HDF1:EnableCallbacks      Disable
New : SIM1:HDF1:EnableCallbacks      Enable
Old : SIM1:HDF2:FilePath \003
New : SIM1:HDF2:FilePath /tmp
Old : SIM1:HDF2:FileName \003
New : SIM1:HDF2:FileName 2test_hdf5
Old : SIM1:HDF2:AutoIncrement        No
New : SIM1:HDF2:AutoIncrement        Yes
Old : SIM1:HDF2:FileTemplate \003
New : SIM1:HDF2:FileTemplate %s%s_%d.h5
Old : SIM1:HDF2:AutoSave             No
New : SIM1:HDF2:AutoSave             Yes
Old : SIM1:HDF2:StorePerform         Yes
New : SIM1:HDF2:StorePerform         Yes
Old : SIM1:HDF2:StoreAttr            Yes
New : SIM1:HDF2:StoreAttr            Yes
Old : SIM1:HDF2:EnableCallbacks      Disable
New : SIM1:HDF2:EnableCallbacks      Enable
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
hinxx     7248 11.0  0.3 4481240 54220 pts/7   Sl+  09:26   0:00 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 40.1  0.3 4481240 61008 pts/7   Sl+  09:26   0:21 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 42.2  0.3 4481240 61008 pts/7   Sl+  09:26   0:43 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.0  0.3 4481240 61008 pts/7   Sl+  09:26   1:06 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.4  0.3 4481240 61008 pts/7   Sl+  09:26   1:28 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.5  0.3 4481240 61008 pts/7   Sl+  09:26   1:50 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.6  0.3 4481240 61008 pts/7   Sl+  09:26   2:12 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.7  0.3 4481240 61008 pts/7   Sl+  09:26   2:34 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.8  0.3 4481240 61008 pts/7   Sl+  09:26   2:57 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.8  0.3 4481240 61008 pts/7   Sl+  09:26   3:19 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.8  0.3 4481240 61008 pts/7   Sl+  09:26   3:41 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.8  0.3 4481240 61008 pts/7   Sl+  09:26   4:03 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.8  0.3 4481240 61008 pts/7   Sl+  09:26   4:25 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.9  0.3 4481240 61008 pts/7   Sl+  09:26   4:47 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.9  0.3 4481240 61008 pts/7   Sl+  09:26   5:09 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.9  0.3 4481240 61008 pts/7   Sl+  09:26   5:31 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.8  0.3 4481240 61008 pts/7   Sl+  09:26   5:52 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.8  0.3 4481240 61008 pts/7   Sl+  09:26   6:14 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.8  0.3 4481240 61008 pts/7   Sl+  09:26   6:36 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.8  0.3 4481240 61008 pts/7   Sl+  09:26   6:59 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.8  0.3 4481240 61008 pts/7   Sl+  09:26   7:21 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.9  0.3 4481240 61008 pts/7   Sl+  09:26   7:43 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.8  0.3 4481240 61008 pts/7   Sl+  09:26   8:05 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.8  0.3 4481240 61008 pts/7   Sl+  09:26   8:27 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.8  0.3 4481240 61008 pts/7   Sl+  09:26   8:49 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.9  0.3 4481240 61008 pts/7   Sl+  09:26   9:11 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.9  0.3 4481240 61008 pts/7   Sl+  09:26   9:33 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.9  0.3 4481240 61008 pts/7   Sl+  09:26   9:55 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.8  0.3 4481240 61008 pts/7   Sl+  09:26  10:17 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.8  0.3 4481240 61008 pts/7   Sl+  09:26  10:39 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.9  0.3 4481240 61008 pts/7   Sl+  09:26  11:01 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.9  0.3 4481240 61008 pts/7   Sl+  09:26  11:23 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.8  0.3 4481240 61008 pts/7   Sl+  09:26  11:44 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.8  0.3 4481240 61008 pts/7   Sl+  09:26  12:07 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.8  0.3 4481240 61008 pts/7   Sl+  09:26  12:29 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.8  0.3 4481240 61008 pts/7   Sl+  09:26  12:51 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.8  0.3 4481240 61008 pts/7   Sl+  09:26  13:13 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.9  0.3 4481240 61008 pts/7   Sl+  09:26  13:35 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.9  0.3 4481240 61008 pts/7   Sl+  09:26  13:57 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.9  0.3 4481240 61008 pts/7   Sl+  09:26  14:19 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.8  0.3 4481240 61008 pts/7   Sl+  09:26  14:39 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.7  0.3 4481240 61008 pts/7   Sl+  09:26  15:00 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.7  0.3 4481240 61008 pts/7   Sl+  09:26  15:22 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.7  0.3 4481240 61008 pts/7   Sl+  09:26  15:44 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.7  0.3 4481240 61008 pts/7   Sl+  09:26  16:06 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.7  0.3 4481240 61008 pts/7   Sl+  09:26  16:28 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.7  0.3 4481240 61008 pts/7   Sl+  09:26  16:50 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.7  0.3 4481240 61008 pts/7   Sl+  09:26  17:12 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.8  0.3 4481240 61008 pts/7   Sl+  09:26  17:34 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.8  0.3 4481240 61008 pts/7   Sl+  09:26  17:57 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.8  0.3 4481240 61008 pts/7   Sl+  09:26  18:18 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.7  0.3 4481240 61008 pts/7   Sl+  09:26  18:40 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.7  0.3 4481240 61008 pts/7   Sl+  09:26  19:00 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.6  0.3 4481240 61008 pts/7   Sl+  09:26  19:19 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.5  0.3 4481240 61008 pts/7   Sl+  09:26  19:40 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.4  0.3 4481240 61008 pts/7   Sl+  09:26  19:59 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.3  0.3 4481240 61008 pts/7   Sl+  09:26  20:18 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.3  0.3 4481240 61008 pts/7   Sl+  09:26  20:39 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.3  0.3 4481240 61008 pts/7   Sl+  09:26  21:01 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.2  0.3 4481240 61008 pts/7   Sl+  09:26  21:20 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.2  0.3 4481240 61008 pts/7   Sl+  09:26  21:41 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.2  0.3 4481240 61008 pts/7   Sl+  09:26  22:02 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.1  0.3 4481240 61008 pts/7   Sl+  09:26  22:22 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.1  0.3 4481240 61008 pts/7   Sl+  09:26  22:42 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.0  0.3 4481240 61008 pts/7   Sl+  09:26  23:01 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 43.0  0.3 4481240 61008 pts/7   Sl+  09:26  23:21 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 42.9  0.3 4481240 61008 pts/7   Sl+  09:26  23:41 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 42.9  0.3 4481240 61008 pts/7   Sl+  09:26  24:01 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 42.8  0.3 4481240 61008 pts/7   Sl+  09:26  24:21 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 42.8  0.3 4481240 61008 pts/7   Sl+  09:26  24:41 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 42.7  0.3 4481240 61008 pts/7   Sl+  09:26  25:01 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 42.7  0.3 4481240 61008 pts/7   Sl+  09:26  25:21 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 42.7  0.3 4481240 61008 pts/7   Sl+  09:26  25:43 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 42.7  0.3 4481240 61008 pts/7   Sl+  09:26  26:02 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 42.6  0.3 4481240 61008 pts/7   Sl+  09:26  26:24 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 42.4  0.3 4481240 61008 pts/7   Sl+  09:26  26:35 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 42.3  0.3 4481240 61008 pts/7   Sl+  09:26  26:51 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 42.3  0.3 4481240 61008 pts/7   Sl+  09:26  27:13 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 42.3  0.3 4481240 61008 pts/7   Sl+  09:26  27:35 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 42.2  0.3 4481240 61008 pts/7   Sl+  09:26  27:54 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 42.2  0.3 4481240 61008 pts/7   Sl+  09:26  28:15 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 42.2  0.3 4481240 61008 pts/7   Sl+  09:26  28:36 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 42.2  0.3 4481240 61008 pts/7   Sl+  09:26  28:58 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 42.3  0.3 4481240 61008 pts/7   Sl+  09:26  29:20 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd
hinxx     7248 42.3  0.3 4481240 61008 pts/7   Sl+  09:26  29:41 /opt/bde/R3.15.5/artifacts/simapp-master/bin/linux-x86_64/iocApp st.cmd

@hinxx
Copy link
Contributor Author

hinxx commented Apr 7, 2019

Script used in the test:
test-hdf5-memlkeak.txt

@hinxx
Copy link
Contributor Author

hinxx commented Apr 7, 2019

I have not tested these changes with attributes or layout XML files supplied to any plugin.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.04%) to 40.306% when pulling b5326bf on hinxx:fix-hdf5-memory-leaks-2 into f485e0b on areaDetector:master.

@ulrikpedersen
Copy link
Member

Thanks for putting in the effort on this one @hinxx - its really very much appriciated!

The initial fix for memory leaks that added a call to H5close() was not proper. It caused IOC crashes if two HDF5 plugin instances were used.

Yikes! Good reason for this PR then 👍

From a quick glance at the changes it looks like we have consistently forgotten to close hdf5 datatype objects - and one instance of a dataspace object.

I added comments to the code paths that I've seen taken (// HK OK). Some other cases I did not test or verify (i.e. error branches) and for those the comment reads // HK test.

That does make it clear what paths you have tested - but we should remove those comments before merging. As a hint for the future: you can actually write these kind of comments 'inline' on the Pull Request here on github...

@MarkRivers
Copy link
Member

I will test this today and if it seems to fix the problem I will merge it, removing the comments.

@MarkRivers MarkRivers merged commit b5326bf into areaDetector:master Apr 8, 2019
@ulrikpedersen
Copy link
Member

I could see messages Failed to create dataset: timestamp. Continuing to next. by using default built-in XML layout.
Is this expected?

I don't think so, no. I'll raise an issue for that one.

I suspect that the in the case of the fail code path is taken there would be leaks.
Looking at this change again, I did not actually test this error case, but assumed that it is OK to have the call in error path, too, since the normal path showed it was needed.

Memory leaks in error paths are probably less critical but still it would be good to eliminate. I see you have raised issue #393 to deal with that.

@hinxx
Copy link
Contributor Author

hinxx commented Apr 9, 2019

I see you have raised issue #393 to deal with that.

That was something I spotted the first time looked around the code to find places for H5close().
As you can see my attempts resulted in segfault for some reason. I did not investigate further. As it appears there was something to fix in the vicinity with with this pull request, but got me thinking that it needs more attention.

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.

4 participants