Closed Blackclaws closed 2 months ago
If you cannot reproduce it, you could try to create a memory dump right when the exception occurs (dotnet-dump collect
, https://learn.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-dump).
Is the problem related with opaque datasets? And if so, is there some varying parameter like the opaque type size or maybe the chunk layout which could produce this flaky behaviour?
So the error seems to pop up erratically but I did manage to get it with a debugger this time and I think I know the source.
It appears the error happens when multiple opaque datasets are used in the same file and they are of different size:
var data = File.ReadAllBytes("/home/felix/Downloads/test.jpg");
var dataTwo = File.ReadAllBytes("/home/felix/dca.jpg");
Console.WriteLine(data.Length);
Console.WriteLine(dataTwo.Length);
var file = new H5File()
{
["opaque"] = new H5Dataset(data, opaqueInfo: new H5OpaqueInfo((uint) data.Length, "Test" )),
["opaque_two"] = new H5Dataset(dataTwo, opaqueInfo: new H5OpaqueInfo((uint) dataTwo.Length, "TestTwo" )),
};
file.Write("testing.h5");
The tag passed to H5OpaqueInfo does not matter (it also doesn't have to be same, but the same or different both show the issue).
Important to failure is only that the first opaque dataset is larger in size than the second one.
Interesting to note:
If the second is larger than the first it will just not get fully written. My guess is that there is again some sort of caching involved here.
I've tracked it down to InternalEncodeDataset giving wrong dataset info back:
var (datatype, encode) =
DatatypeMessage.Create(Context, memoryData, isScalar, dataset.OpaqueInfo);
Further tracked it down to this:
// special case: opaque (= byte[])
// use unique type to make cache happy
if (type == typeof(byte) && opaqueInfo is not null)
type = typeof(H5OpaqueInfo);
I think the problem is that it works fine for the first H5OpaqueInfo but because the size is different for each opaque set you can't cache it at all.
I'm going to create a fix and pull request for it.
Thanks for debugging!
1.0.0-beta.15 includes the fix!
So from time to time I get these errors:
without any clear way on how to reproduce them. I'm not firm enough on the internals of PureHDF to even begin to debug this but maybe you have an idea what might be going wrong.
The resulting file that is written is then broken.