-
Notifications
You must be signed in to change notification settings - Fork 289
Kill testhost if writing hang dump fails #5538
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -379,42 +379,48 @@ | |
|
|
||
| await _outputDisplay.DisplayAsync(this, new ErrorMessageOutputDeviceData(string.Format(CultureInfo.InvariantCulture, ExtensionResources.CreatingDumpFile, finalDumpFileName))); | ||
|
|
||
| #if NETCOREAPP | ||
| DiagnosticsClient diagnosticsClient = new(_testHostProcessInformation.PID); | ||
| DumpType dumpType = _dumpType.ToLowerInvariant().Trim() switch | ||
| { | ||
| "mini" => DumpType.Normal, | ||
| "heap" => DumpType.WithHeap, | ||
| "triage" => DumpType.Triage, | ||
| "full" => DumpType.Full, | ||
| _ => 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(' ')) | ||
| try | ||
| { | ||
| finalDumpFileName = $"\"{finalDumpFileName}\""; | ||
| } | ||
|
|
||
| diagnosticsClient.WriteDump(dumpType, finalDumpFileName, true); | ||
| #if NETCOREAPP | ||
| DiagnosticsClient diagnosticsClient = new(_testHostProcessInformation.PID); | ||
| DumpType dumpType = _dumpType.ToLowerInvariant().Trim() switch | ||
| { | ||
| "mini" => DumpType.Normal, | ||
| "heap" => DumpType.WithHeap, | ||
| "triage" => DumpType.Triage, | ||
| "full" => DumpType.Full, | ||
| _ => 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}\""; | ||
| } | ||
|
|
||
|
Check failure on line 401 in src/Platform/Microsoft.Testing.Extensions.HangDump/HangDumpProcessLifetimeHandler.cs
|
||
Youssef1313 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| diagnosticsClient.WriteDump(dumpType, finalDumpFileName, true); | ||
| #else | ||
| MiniDumpWriteDump.MiniDumpTypeOption miniDumpTypeOption = _dumpType.ToLowerInvariant().Trim() switch | ||
| { | ||
| "mini" => MiniDumpWriteDump.MiniDumpTypeOption.Mini, | ||
| "heap" => MiniDumpWriteDump.MiniDumpTypeOption.Heap, | ||
| "full" => MiniDumpWriteDump.MiniDumpTypeOption.Full, | ||
| _ => throw ApplicationStateGuard.Unreachable(), | ||
| }; | ||
| MiniDumpWriteDump.MiniDumpTypeOption miniDumpTypeOption = _dumpType.ToLowerInvariant().Trim() switch | ||
| { | ||
| "mini" => MiniDumpWriteDump.MiniDumpTypeOption.Mini, | ||
| "heap" => MiniDumpWriteDump.MiniDumpTypeOption.Heap, | ||
| "full" => MiniDumpWriteDump.MiniDumpTypeOption.Full, | ||
| _ => throw ApplicationStateGuard.Unreachable(), | ||
| }; | ||
|
|
||
| MiniDumpWriteDump.CollectDumpUsingMiniDumpWriteDump(_testHostProcessInformation.PID, finalDumpFileName, miniDumpTypeOption); | ||
| MiniDumpWriteDump.CollectDumpUsingMiniDumpWriteDump(_testHostProcessInformation.PID, finalDumpFileName, miniDumpTypeOption); | ||
| #endif | ||
|
|
||
| NotifyCrashDumpServiceIfEnabled(); | ||
| using IProcess process = _processHandler.GetProcessById(_testHostProcessInformation.PID); | ||
| process.Kill(); | ||
| await process.WaitForExitAsync(); | ||
| _dumpFileTaken = finalDumpFileName; | ||
| _dumpFileTaken = finalDumpFileName; | ||
| } | ||
| finally | ||
| { | ||
| NotifyCrashDumpServiceIfEnabled(); | ||
| using IProcess process = _processHandler.GetProcessById(_testHostProcessInformation.PID); | ||
| process.Kill(); | ||
| await process.WaitForExitAsync(); | ||
| } | ||
| } | ||
|
|
||
| private static void NotifyCrashDumpServiceIfEnabled() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.