I have a bit of a strange problem. I'm running a web API on ASP.NET Core 3.1. One thing the API does is to generate a SHA256 from an input string
private static HashAlgorithm algorithm = SHA256.Create();
public static byte[] GetSha256Hash(string inputString)
{
return algorithm.ComputeHash(Encoding.UTF8.GetBytes(inputString));
}
public static string GetSha256HashString(string inputString)
{
var result = GetSha256Hash(inputString);
// Return as hexadecimal string
return string.Join(
string.Empty,
result.Select(x => x.ToString("x2")));
}
player.Id = GetSha256HashString($"{player.Name}-{player.Region}-{player.Country}");
I check that the fields player.Name, region and country and not null before I do the hashing. But sometimes, mostly seems to happen when the server is under heavy load (~100 requests/second), for a few requests (about ~0.5%) it generates
0000000000000000000000000000000000000000000000000000000000000000
for the player.id. Usually they look something like this a7da37b8a57ea714ec11f92c0025d6e654a483144eb68b829d388ea91eb81c79
Even if all the fields would be empty, the three dashes alone would ensure that this should not happen.
I do not see any exceptions and I am a bit out of ideas how to debug this. Any help is welcome! Let me know if I need to add any more information.
Env: Running in Docker on Linux.