-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Crash on WindowsCryptographicException on net60 GA #61417
Comments
Tagging subscribers to this area: @bartonjs, @vcsjones, @krwq, @GrabYourPitchforks Issue DetailsDescriptionSystem.AggregateException: One or more errors occurred. (Unknown error (0xc1000008)) Reproduction StepsThe app in question is a simple web host, accessing the page via the edge browser. Expected behaviorNo crash Actual behaviorProcess crashes hard with an uncaught exception Regression?Yes. The issue never happen till I installed the net60 GA SDK installed this morning. Known WorkaroundsNo response ConfigurationWindow x64 dotnet --list-sdks
Other informationNo response
|
If it helps, here is a crash dump |
A few questions that might help tracking down the issue:
|
@vcsjones It looks like I'm running into the same thing, also after an update to net60 after the app worked fine in net50. It's intermittent and unpredictable, and in my case it's in a 3rd-party library but with a similar upper portion of the stack trace:
Windows 10 v21H2 (OS Build 19044.1348) |
A few guesses, since I don't have a lot to go on.
I suspect it is might be because the I can reproduce this exception by using an using System;
using System.Threading;
using System.Security.Cryptography;
using HMACSHA512 hmac = new HMACSHA512();
Thread thread1 = new Thread(static obj => {
while (true)
{
((HMACSHA512)obj).ComputeHash(new byte[1]);
}
});
Thread thread2 = new Thread(static obj => {
while (true)
{
((HMACSHA512)obj).ComputeHash(new byte[1]);
}
});
thread1.Start(hmac);
thread2.Start(hmac);
thread1.Join();
thread2.Join(); That will quickly give me the same issue as described in the original post. At this point I can only suggest that you confirm with the library author that no instance of a hash or HMAC algorithm is being used by two or more threads, concurrently. If that is indeed the case, I would recommend creating a new instance of the hash / HMAC algorithm per-thread, or just always as-needed. Alternatively, using the |
Hi @vcsjones thanks for the suggestion, I'll investigate if this is the case on my side. It should have been a single thread accessing it, but I'll double check it |
This issue has been marked |
@vcsjones I have a repro case for a similar, if not identical, issue: This breaks:
If you want things to break in .NET6 just leave the 4th line commented. If you want it to not break, uncomment line 4. If you re-initialize a hasher after calling TransformBlock and before calling TransformFinalBlock, you corrupt the hasher and it fails. EDIT: Thanks to @EvgeniyZ-ru for bringing this issue to my attention, and working with me to provide the information I needed to distill a testcase :) |
I took a few minutes and reduced it a bit further:
|
If you call Initialize on a hash algorithm, after you've invoked TransformBlock but before you've invoked TransformFinalBlock, the instance corrupts and mysteriously fails to transform blocks later on. Works around dotnet/runtime#61417 Addresses #483
Thanks for the test case, I can reproduce it now. I will look at this now. |
I have a PR open to address the issue uncovered by @alanmcgovern's test case. This won't fix @jaylagorio's reported instance - sharing an instance between threads will still lead to the same issue of the CNG object getting in to an incorrect state. This particular issue is new in .NET 6 because prior to .NET 6, the @theolivenbaum can you confirm if this is the issue you were running in to as well? Are you using |
I just noticed on @theolivenbaum's stack This to me implies a possibility that the hash object is being used concurrently from different It's not definitive evidence, but a possibility. |
@vcsjones Thanks so much for looking into this and thanks even more for submitting a PR to the library I'm using! Fingers crossed for a new release soon. |
Not sure if related @vcsjones, but I'm also using SHA256.ComputeHash(...), and it throws randomly this:
|
The code is approximately this: var files = new []{ "path to file", ... }; //list of files
await Task.WhenAll(files.Select(async f => await DoSomethingWithFile(f, Sha256.ComputeHash(await File.ReadAllBytesAsync(f))))); |
It also throws this on subsequent calls:
|
It looks like you are using an instance of If you are targeting var files = new []{ "path to file", ... }; //list of files
await Task.WhenAll(files.Select(async f => await DoSomethingWithFile(f, SHA256.HashData(await File.ReadAllBytesAsync(f)))));
|
True, I thought I was already using the static method 🤦♂️ |
To round things out here:
|
Hi @vcsjones, I've not observed the issue anymore! Nice to hear it uncovered another issue nevertheless! Thanks! |
Description
System.AggregateException: One or more errors occurred. (Unknown error (0xc1000008))
---> Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: Unknown error (0xc1000008)
at Internal.Cryptography.HashProviderCng.AppendHashData(ReadOnlySpan`1 source)
at Internal.Cryptography.HashProvider.AppendHashData(Byte[] data, Int32 offset, Int32 count)
at System.Security.Cryptography.SHA256.Implementation.HashCore(Byte[] array, Int32 ibStart, Int32 cbSize)
at System.Security.Cryptography.HashAlgorithm.ComputeHash(Byte[] buffer)
at Host.CLI.Program.<>c__DisplayClass9_2.<b__3>d.MoveNext() in C:\work\curiosity\curiosity-ai-website\tools\host\Program.cs:line 280
--- End of stack trace from previous location ---
at Host.CLI.Program.BuildAsync(String path, String buildPath, String templatePath, String translationPath) in C:\work\curiosity\curiosity-ai-website\tools\host\Program.cs:line 296
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()
at Host.CLI.Delayed.g__CheckBacklog|5_1() in C:\work\curiosity\curiosity-ai-website\tools\host\Delayed.cs:line 71
at Host.CLI.Delayed.<>c.b__5_0(Object _) in C:\work\curiosity\curiosity-ai-website\tools\host\Delayed.cs:line 49
at System.Threading.TimerQueueTimer.<>c.<.cctor>b__27_0(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.TimerQueueTimer.CallCallback(Boolean isThreadPool)
at System.Threading.TimerQueueTimer.Fire(Boolean isThreadPool)
at System.Threading.TimerQueue.FireNextTimers()
at System.Threading.TimerQueue.AppDomainTimerCallback(Int32 id)
Reproduction Steps
The app in question is a simple web host, accessing the page via the edge browser.
Expected behavior
No crash
Actual behavior
Process crashes hard with an uncaught exception
Regression?
Yes. The issue never happen till I installed the net60 GA SDK installed this morning.
Known Workarounds
No response
Configuration
Window x64
dotnet --list-sdks
Other information
No response
The text was updated successfully, but these errors were encountered: