Skip to content

dotnet-dump collect returning invalid dump file  #3829

Closed

Description

@Applesauce314

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.

// 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

  1. added
    bug
    on Apr 13, 2023
  2. self-assigned this
    on Apr 13, 2023
  3. added this to the 8.0.0 milestone on Apr 13, 2023
  4. mikem8361 commented on Apr 13, 2023

    @mikem8361
    Contributor

    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.

  5. Applesauce314 commented on Apr 13, 2023

    @Applesauce314
    ContributorAuthor

    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?

  6. Applesauce314 commented on Apr 25, 2023

    @Applesauce314
    ContributorAuthor

    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...

  7. mikem8361 commented on Apr 25, 2023

    @mikem8361
    Contributor

    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.

  8. Applesauce314 commented on Apr 26, 2023

    @Applesauce314
    ContributorAuthor

    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.

  9. mikem8361 commented on Apr 26, 2023

    @mikem8361
    Contributor

    There is a chance that DiagnosticsClient.WriteDump behaves better but createdump.exe calls MiniDumpWriteDump after the runtime launches it. See createdump.

  10. added a commit that references this issue on Apr 27, 2023
  11. ghost locked as resolved and limited conversation to collaborators on Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions