Repository navigation
Description
Description
while trying to debug a thrashing asp.net core process we collected dumps using dotnet-dump collect. But when trying to open the dump file with dotnet-dump analyze nothing happens.
Investigation
When debugging the load of the dump file, I found that it is not finding a system info stream in the dump. Exception thrown here
looking at the mindump file and comparing to other minidumps that open correctly It appears that the array of MINIDUMP_DIRECTORY pointed to by the MINIDUMP_HEADER is filled with 0s instead of valid MINIDUMP_DIRECTORY entries.
Theory
the only way that dotnet-dump collect can return without error is if it gets an HResult of ERROR_PARTIAL_COPY 5 times or the underlying API call is not erroring.
diagnostics/src/Tools/dotnet-dump/Dumper.Windows.cs
Lines 70 to 86 in a66abfc
| // Retry the write dump on ERROR_PARTIAL_COPY | |
| for (int i = 0; i < 5; i++) | |
| { | |
| // Dump the process! | |
| if (NativeMethods.MiniDumpWriteDump(processHandle.DangerousGetHandle(), (uint)processId, stream.SafeFileHandle, dumpType, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero)) | |
| { | |
| break; | |
| } | |
| else | |
| { | |
| int err = Marshal.GetHRForLastWin32Error(); | |
| if (err != NativeMethods.HR_ERROR_PARTIAL_COPY) | |
| { | |
| Marshal.ThrowExceptionForHR(err); | |
| } | |
| } | |
| } |
It seems unlikely that the windows api call to minidumpwritedump is failing without returning an error so my suspicion is that it is getting the ERROR_PARTIAL_COPY error 5 times then returning without providing this feedback.
Configuration
dotnet-dump version 6.0.351802+ca25fd472e7dd6501d4a85973e0d0326c856880d
Windows Server 2016
dotnet-dump is using installed 3.1.32 for .net core runtime and hosting
thrashing process is using 6.0.12 runtime (SelfContained)
Activity
mikem8361 commentedon Apr 13, 2023
Yes, it does look like we forgot to throw an exception with a ERROR_PARTIAL_COPY after failing 5 times. That I get fixed. The problem is why it would fail 5 times. That is very rare.
If you had the time to clone the diagnostics repo, change this code to retry 10 times and throw an exception outside the retry for(), it would be helpful.
Applesauce314 commentedon Apr 13, 2023
I was planning on creating a pull request to fix this. and to test on our server.
as a point of interest, do you know under what circumstances ERROR_PARTIAL_COPY might be returned?
Applesauce314 commentedon Apr 25, 2023
Just to follow up, the above was why I was getting a invalid dump file. We had our issue again and using a local build of dotnet-dump with the changes made here ran collect. the collect reported the retries and then reported the failure after the final retry failed.
Unfortunately, that just means I now know why my dump is corrupt, but not why my process is failing...
mikem8361 commentedon Apr 25, 2023
It has always been unclear why and when Windows returns ERROR_PARTIAL_COPY just that we need to do this retry on older versions of Windows. I've never heard of needing more than 5 retries (and it still fails for you after it was upped to 10).
We can re-open this issue to track doing research on this, but I'm not sure when that will happen.
Applesauce314 commentedon Apr 26, 2023
If you think there is more we can do on the tooling side to figure this one out, (e.g. could we maybe get something useful from the MiniDumpWriteDump Callback? or would we get a different result using the DiagnosticClient.WriteDump?).
Otherwise I would expect its more a problem for Windows, or the .Net runtime, not the diagnostic tools repo.
mikem8361 commentedon Apr 26, 2023
There is a chance that DiagnosticsClient.WriteDump behaves better but createdump.exe calls MiniDumpWriteDump after the runtime launches it. See createdump.
Update createdumpwindows.cpp
Update createdumpwindows to not appear to succeed after getting ERROR…