You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
System.Security.Cryptography.CryptographicException : Concurrent operations from multiple threads on this type are not supported.
Stack Trace:
at System.Security.Cryptography.ConcurrencyBlock.Enter(ConcurrencyBlock& block)
at System.Security.Cryptography.HashProviderDispenser.EvpHashProvider.AppendHashData(ReadOnlySpan`1 data)
at System.Security.Cryptography.HashProvider.AppendHashData(Byte[] data, Int32 offset, Int32 count)
at System.Security.Cryptography.HashAlgorithm.ComputeHash(Byte[] buffer)
at FluentStorage.Utils.Extensions.ByteArrayExtensions.MD5(Byte[] bytes)
at FluentStorage.Blobs.InMemoryBlobStorage.Write(String fullPath, Stream sourceStream)
at FluentStorage.Blobs.InMemoryBlobStorage.WriteAsync(String fullPath, Stream sourceStream, Boolean append, CancellationToken cancellationToken)
By reading some threads like dotnet/runtime#93205 (comment) and dotnet/runtime#93205, It seems that reusing the crypto object at FluentStorage.Blobs.InMemoryBlobStorage.Write function is not safe for multi threads as from dotnet 8.
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.
The text was updated successfully, but these errors were encountered:
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.
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 dotnet/runtime#93205 (comment) and dotnet/runtime#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.
The text was updated successfully, but these errors were encountered: