Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -372,20 +372,15 @@ private async Task TakeDumpAsync(IProcess process, CancellationToken cancellatio
_ => throw ApplicationStateGuard.Unreachable(),
};

// Wrap the dump path into "" when it has space in it, this is a workaround for this runtime issue: https://github.com/dotnet/diagnostics/issues/5020
// It only affects windows. Otherwise the dump creation fails with: [createdump] The pid argument is no longer supported
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && finalDumpFileName.Contains(' '))
{
finalDumpFileName = $"\"{finalDumpFileName}\"";
}
DumpFileNames dumpFileNames = GetDumpFileNames(finalDumpFileName);

try
{
// Skip creating the dump if the option is set to none, and just kill the process.
if (dumpType.HasValue)
{
diagnosticsClient.WriteDump(dumpType.Value, finalDumpFileName, logDumpGeneration: false);
_dumpFiles.Add(finalDumpFileName);
diagnosticsClient.WriteDump(dumpType.Value, dumpFileNames.WriteDumpFileName, logDumpGeneration: false);
_dumpFiles.Add(dumpFileNames.ArtifactDumpFileName);
}
}
catch (Exception e)
Expand Down Expand Up @@ -421,6 +416,17 @@ private async Task TakeDumpAsync(IProcess process, CancellationToken cancellatio
#endif
}

// Wrap the dump path into "" when it has space in it, this is a workaround for this runtime issue: https://github.com/dotnet/diagnostics/issues/5020
// It only affects windows. Otherwise the dump creation fails with: [createdump] The pid argument is no longer supported
internal static DumpFileNames GetDumpFileNames(string dumpFileName)
=> new(
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && dumpFileName.Contains(' ')
? $"\"{dumpFileName}\""
: dumpFileName,
dumpFileName);

internal readonly record struct DumpFileNames(string WriteDumpFileName, string ArtifactDumpFileName);

private static void NotifyCrashDumpServiceIfEnabled()
=> AppDomain.CurrentDomain.SetData("ProcessKilledByHangDump", "true");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,16 @@ public async Task If_HangDumpMainOption_IsSpecified_ShouldReturn_IsValid(string
Assert.IsTrue(validateOptionsResult.IsValid);
Assert.IsTrue(string.IsNullOrEmpty(validateOptionsResult.ErrorMessage));
}

[TestMethod]
[OSCondition(ConditionMode.Include, OperatingSystems.Windows, IgnoreMessage = "Validates Windows-specific quoting workaround for dotnet/diagnostics#5020")]
public void GetDumpFileNames_WindowsPathWithSpaces_QuotesOnlyWriteDumpArgument()
{
string dumpFileName = @"C:\results directory with spaces\hangdump.dmp";

HangDumpProcessLifetimeHandler.DumpFileNames dumpFileNames = HangDumpProcessLifetimeHandler.GetDumpFileNames(dumpFileName);

Assert.AreEqual($"\"{dumpFileName}\"", dumpFileNames.WriteDumpFileName);
Assert.AreEqual(dumpFileName, dumpFileNames.ArtifactDumpFileName);
}
}
Loading