Open jonasof opened 2 months ago
Hi @jonasof, I had the same problem for SHA256, option 2 you mentioned solved it for me.
I was able to resolve this issue by using the static HashData
method rather than calling ComputeHash
on an instance. The static methods are guaranteed to be thread safe.
return SHA256.HashData(bytes);
Hi, I'm using the in-memory version for unit tests in a linux container with dotnet 8, I'm getting this exception while writing files:
To simplify the reproduction I made this code:
By reading some threads like https://github.com/dotnet/runtime/issues/93205#issuecomment-2226282536 and https://github.com/dotnet/runtime/issues/93205, It seems that reusing the crypto object at FluentStorage.Blobs.InMemoryBlobStorage.Write function is not safe for multi threads as from dotnet 8.
Some alternative I see to solve the issue are:
1 - Instantiate the crypto at every call, like
Crypto.SHA256.Create().ComputeHash(bytes)
instead of_md5.ComputeHash(bytes)
. I've tried it and it solved the issue; However i'm not sure about the performance cost. 2 - Use Crypto.MD5.HashData(bytes). It's only available after dotnet 7 and I haven't tested it.Thank you for the support.